diff --git a/src/dnspr.c b/src/dnspr.c index 9a3fb01..532a13a 100644 --- a/src/dnspr.c +++ b/src/dnspr.c @@ -147,9 +147,9 @@ void * dnsprchild(struct clientparam* param) { } else { #ifdef _WIN32 -/* ioctlsocket(param->remsock, FIONBIO, &ul); */ + ioctlsocket(param->remsock, FIONBIO, &ul); #else -/* fcntl(param->remsock,F_SETFL,O_NONBLOCK); */ + fcntl(param->remsock, F_SETFL, O_NONBLOCK | fcntl(param->remsock, F_GETFL)); #endif } diff --git a/src/socks.c b/src/socks.c index 61b656b..7597708 100644 --- a/src/socks.c +++ b/src/socks.c @@ -255,6 +255,11 @@ void * sockschild(struct clientparam* param) { if(switch_ns(param->srv, param->srv->o_nsfd)) {RETURN(11);} #endif if ((param->remsock=param->srv->so._socket(param->sostate, SASOCK(¶m->req), SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {RETURN (11);} +#ifdef _WIN32 + { unsigned long ul = 1; ioctlsocket(param->remsock, FIONBIO, &ul); } +#else + fcntl(param->remsock, F_SETFL, O_NONBLOCK | fcntl(param->remsock, F_GETFL)); +#endif } if(command > 1) { @@ -275,6 +280,11 @@ fflush(stderr); #endif param->clisock = param->srv->so._socket(param->sostate, SASOCK(¶m->sincr), SOCK_DGRAM, IPPROTO_UDP); if(param->clisock == INVALID_SOCKET) {RETURN(11);} +#ifdef _WIN32 + { unsigned long ul = 1; ioctlsocket(param->clisock, FIONBIO, &ul); } +#else + fcntl(param->clisock, F_SETFL, O_NONBLOCK | fcntl(param->clisock, F_GETFL)); +#endif sin = param->sincl; *SAPORT(&sin) = 0; if(param->srv->so._bind(param->sostate, param->clisock,(struct sockaddr *)&sin,SASIZE(&sin))) {RETURN (12);} diff --git a/src/udpsockmap.c b/src/udpsockmap.c index ec7c346..f450a0e 100644 --- a/src/udpsockmap.c +++ b/src/udpsockmap.c @@ -106,6 +106,7 @@ int udpsockmap(struct clientparam *param, int timeo) len = param->srv->so._recvfrom(param->sostate, param->clisock, (char *)param->srvbuf + recvoff, UDPBUFSIZE - recvoff, 0, (struct sockaddr *)&sin, &sasize); + if (len < 0 && (errno == EAGAIN || errno == EINTR)) continue; if (len <= 0) return 482; if (SAADDRLEN(&sin) != SAADDRLEN(¶m->sincr) || @@ -182,6 +183,7 @@ int udpsockmap(struct clientparam *param, int timeo) len = param->srv->so._recvfrom(param->sostate, param->remsock, (char *)param->srvbuf + hdrsize, UDPBUFSIZE - hdrsize, 0, (struct sockaddr *)&from, &sasize); + if (len < 0 && (errno == EAGAIN || errno == EINTR)) continue; if (len <= 0) return 486; if (nhops >= 1) { if (!SAISNULL(¶m->sinsr) && *SAPORT(¶m->sinsr)) {