mirror of
https://github.com/3proxy/3proxy.git
synced 2026-06-10 09:50:12 +08:00
Use non-blocking sockets for UDP
This commit is contained in:
parent
ab11e6c4a3
commit
fd7b25bf06
@ -147,9 +147,9 @@ void * dnsprchild(struct clientparam* param) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* ioctlsocket(param->remsock, FIONBIO, &ul); */
|
ioctlsocket(param->remsock, FIONBIO, &ul);
|
||||||
#else
|
#else
|
||||||
/* fcntl(param->remsock,F_SETFL,O_NONBLOCK); */
|
fcntl(param->remsock, F_SETFL, O_NONBLOCK | fcntl(param->remsock, F_GETFL));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
src/socks.c
10
src/socks.c
@ -255,6 +255,11 @@ void * sockschild(struct clientparam* param) {
|
|||||||
if(switch_ns(param->srv, param->srv->o_nsfd)) {RETURN(11);}
|
if(switch_ns(param->srv, param->srv->o_nsfd)) {RETURN(11);}
|
||||||
#endif
|
#endif
|
||||||
if ((param->remsock=param->srv->so._socket(param->sostate, SASOCK(¶m->req), SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {RETURN (11);}
|
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) {
|
if(command > 1) {
|
||||||
@ -275,6 +280,11 @@ fflush(stderr);
|
|||||||
#endif
|
#endif
|
||||||
param->clisock = param->srv->so._socket(param->sostate, SASOCK(¶m->sincr), SOCK_DGRAM, IPPROTO_UDP);
|
param->clisock = param->srv->so._socket(param->sostate, SASOCK(¶m->sincr), SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if(param->clisock == INVALID_SOCKET) {RETURN(11);}
|
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;
|
sin = param->sincl;
|
||||||
*SAPORT(&sin) = 0;
|
*SAPORT(&sin) = 0;
|
||||||
if(param->srv->so._bind(param->sostate, param->clisock,(struct sockaddr *)&sin,SASIZE(&sin))) {RETURN (12);}
|
if(param->srv->so._bind(param->sostate, param->clisock,(struct sockaddr *)&sin,SASIZE(&sin))) {RETURN (12);}
|
||||||
|
|||||||
@ -106,6 +106,7 @@ int udpsockmap(struct clientparam *param, int timeo)
|
|||||||
len = param->srv->so._recvfrom(param->sostate, param->clisock,
|
len = param->srv->so._recvfrom(param->sostate, param->clisock,
|
||||||
(char *)param->srvbuf + recvoff, UDPBUFSIZE - recvoff,
|
(char *)param->srvbuf + recvoff, UDPBUFSIZE - recvoff,
|
||||||
0, (struct sockaddr *)&sin, &sasize);
|
0, (struct sockaddr *)&sin, &sasize);
|
||||||
|
if (len < 0 && (errno == EAGAIN || errno == EINTR)) continue;
|
||||||
if (len <= 0) return 482;
|
if (len <= 0) return 482;
|
||||||
|
|
||||||
if (SAADDRLEN(&sin) != SAADDRLEN(¶m->sincr) ||
|
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,
|
len = param->srv->so._recvfrom(param->sostate, param->remsock,
|
||||||
(char *)param->srvbuf + hdrsize, UDPBUFSIZE - hdrsize, 0,
|
(char *)param->srvbuf + hdrsize, UDPBUFSIZE - hdrsize, 0,
|
||||||
(struct sockaddr *)&from, &sasize);
|
(struct sockaddr *)&from, &sasize);
|
||||||
|
if (len < 0 && (errno == EAGAIN || errno == EINTR)) continue;
|
||||||
if (len <= 0) return 486;
|
if (len <= 0) return 486;
|
||||||
if (nhops >= 1) {
|
if (nhops >= 1) {
|
||||||
if (!SAISNULL(¶m->sinsr) && *SAPORT(¶m->sinsr)) {
|
if (!SAISNULL(¶m->sinsr) && *SAPORT(¶m->sinsr)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user