Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kehengzhong authored Sep 4, 2021
1 parent cf2aa50 commit cb0fab6
Show file tree
Hide file tree
Showing 15 changed files with 1,792 additions and 201 deletions.
18 changes: 15 additions & 3 deletions src/epcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include "mlisten.h"
#include "epdns.h"

#ifdef HAVE_IOCP
#include "epiocp.h"
#endif

#ifdef UNIX

#include <sys/resource.h>
Expand Down Expand Up @@ -63,11 +67,11 @@ static int set_fd_limit(int max)
void * epcore_new (int maxfd, int dispmode)
{
epcore_t * pcore = NULL;
#ifdef _WIN32
#if defined(_WIN32) || defined(_WIN64)
WSADATA wsd;
#endif

#ifdef _WIN32
#if defined(_WIN32) || defined(_WIN64)
if (WSAStartup (MAKEWORD(2,2), &wsd) != 0) {
return NULL;
}
Expand All @@ -94,6 +98,10 @@ void * epcore_new (int maxfd, int dispmode)
#endif
pcore->wakeupdev = NULL;

#ifdef HAVE_IOCP
epcore_iocp_init(pcore);
#endif

/* initialize memory pool resource */
if (!pcore->device_pool) {
pcore->device_pool = bpool_init(NULL);
Expand Down Expand Up @@ -215,6 +223,10 @@ void epcore_clean (void * vpcore)

epcore_wakeup_clean(pcore);

#ifdef HAVE_IOCP
epcore_iocp_clean(pcore);
#endif

/* release all memory pool resource */
bpool_clean(pcore->timer_pool);
bpool_clean(pcore->device_pool);
Expand All @@ -223,7 +235,7 @@ void epcore_clean (void * vpcore)

kfree(pcore);

#ifdef _WIN32
#if defined(_WIN32) || defined(_WIN64)
WSACleanup();
#endif
}
Expand Down
39 changes: 20 additions & 19 deletions src/epdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ int dns_nsrv_load (void * vmgmt, char * nsip, char * resolv_file)
char * p = NULL;
int len = 0;
#endif
#ifdef _WIN32
#if defined(_WIN32) || defined(_WIN64)
FIXED_INFO fi;
ULONG ulen = sizeof(fi);
IP_ADDR_STRING * paddr = NULL;
Expand Down Expand Up @@ -266,7 +266,7 @@ int dns_nsrv_load (void * vmgmt, char * nsip, char * resolv_file)
fclose(fp);
#endif

#ifdef _WIN32
#if defined(_WIN32) || defined(_WIN64)
/* retrieves network parameters for the local computer */
if (GetNetworkParams(&fi, &ulen) != ERROR_SUCCESS) {
return -100;
Expand Down Expand Up @@ -1569,7 +1569,8 @@ int dns_msg_send (void * vmsg, char * name, int len, void * vnsrv)
DnsNSrv * nsrv = (DnsNSrv *)vnsrv;
DnsMgmt * mgmt = NULL;
DnsHost * host = NULL;
int i, num, ret;
iodev_t * pdev = NULL;
int i, j, num, ret;

if (!msg) return -1;

Expand Down Expand Up @@ -1604,7 +1605,13 @@ int dns_msg_send (void * vmsg, char * name, int len, void * vnsrv)
host = arr_value(nsrv->host_list, (i + msg->nsrvind) % num);
if (!host) continue;

ret = sendto(iodev_fd(mgmt->cli_dev),
for (j = 0; j < mgmt->cli_dev_num; j++) {
pdev = mgmt->cli_dev[j];
if (pdev->family == host->addr.u.addr.sa_family)
break;
}

ret = sendto(iodev_fd(pdev),
frameP(msg->reqfrm),
frameL(msg->reqfrm), 0,
(struct sockaddr *)&host->addr.u.addr,
Expand Down Expand Up @@ -1838,14 +1845,16 @@ void * dns_mgmt_init (void * pcore, char * nsip, char * resolv_file)

mgmt->pcore = pcore;

mgmt->cli_dev = epudp_client(pcore, NULL, 0, mgmt, NULL, dns_pump, mgmt);
mgmt->cli_dev_num = 4;
epudp_client(pcore, NULL, 0, mgmt, NULL, dns_pump, mgmt, mgmt->cli_dev, &mgmt->cli_dev_num);

return mgmt;
}

void dns_mgmt_clean (void * vmgmt)
{
DnsMgmt * mgmt = (DnsMgmt *)vmgmt;
int i;

if (!mgmt) return;

Expand All @@ -1854,7 +1863,8 @@ void dns_mgmt_clean (void * vmgmt)
mgmt->cachetimer = NULL;
}

iodev_close(mgmt->cli_dev);
for (i = 0; i < mgmt->cli_dev_num; i++)
iodev_close(mgmt->cli_dev[i]);

dns_nsrv_free(mgmt->nsrv);

Expand Down Expand Up @@ -1922,8 +1932,6 @@ int dns_recv (void * vmgmt, void * pobj)
DnsMgmt * mgmt = (DnsMgmt *)vmgmt;
iodev_t * pdev = (iodev_t *)pobj;
ep_sockaddr_t sock;
int socklen = 0;
int toread = 0;
int ret = 0;
frame_t * frm = NULL;
uint16 msgid = 0;
Expand All @@ -1932,21 +1940,14 @@ int dns_recv (void * vmgmt, void * pobj)
if (!mgmt) return -1;

while (1) {
toread = sock_unread_data(iodev_fd(pdev));
if (toread <= 0) break;

frm = frame_new(toread);

socklen = sizeof(sock);
memset(&sock, 0, sizeof(sock));
ret = recvfrom(iodev_fd(pdev), frameP(frm), toread, 0,
(struct sockaddr *)&sock, (socklen_t *)&socklen);
frm = frame_new(0);

ret = epudp_recvfrom(pdev, frm, &sock, NULL);
if (ret <= 0) {
frame_free(frm);
return 0;
}
frame_len_set(frm, ret);


frame_readn(frm, 0, &msgid, 2);
msgid = ntohs(msgid);

Expand Down
6 changes: 0 additions & 6 deletions src/epepoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ int epump_epoll_setpoll (void * vepump, void * vpdev)

ret = epoll_ctl(epump->epoll_fd, op, pdev->fd, &ev);
if (ret >= 0) {
pdev->epev = curev;
return 0;
}

Expand All @@ -136,8 +135,6 @@ int epump_epoll_setpoll (void * vepump, void * vpdev)

if (ret < 0) return -1;

pdev->epev = curev;

return 0;
}

Expand All @@ -156,9 +153,6 @@ int epump_epoll_clearpoll (void * vepump, void * vpdev)
memset(&ev, 0, sizeof(ev));

ret = epoll_ctl(epump->epoll_fd, EPOLL_CTL_DEL, pdev->fd, &ev);
if (ret >= 0) {
pdev->epev = 0;
}

return ret;
}
Expand Down
Loading

0 comments on commit cb0fab6

Please sign in to comment.