mirror of
https://github.com/3proxy/3proxy.git
synced 2025-02-24 02:55:40 +08:00
implement timeout on connect()
STRING_S timeout is used (15 sec by default)
This commit is contained in:
parent
c5f8a8e139
commit
d1d86ed9b3
26
src/common.c
26
src/common.c
@ -702,17 +702,31 @@ int doconnect(struct clientparam * param){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(param->operation >= 256 || (param->operation & CONNECT)){
|
if(param->operation >= 256 || (param->operation & CONNECT)){
|
||||||
|
struct pollfd fds[1];
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
unsigned long ul = 1;
|
unsigned long ul = 1;
|
||||||
#endif
|
|
||||||
if(so._connect(param->remsock,(struct sockaddr *)¶m->sinsr,SASIZE(¶m->sinsr))) {
|
|
||||||
return (13);
|
|
||||||
}
|
|
||||||
param->nconnects++;
|
|
||||||
#ifdef _WIN32
|
|
||||||
ioctlsocket(param->remsock, FIONBIO, &ul);
|
ioctlsocket(param->remsock, FIONBIO, &ul);
|
||||||
#else
|
#else
|
||||||
|
socklen_t us = sizeof(ul);
|
||||||
fcntl(param->remsock,F_SETFL,O_NONBLOCK);
|
fcntl(param->remsock,F_SETFL,O_NONBLOCK);
|
||||||
|
#endif
|
||||||
|
if(so._connect(param->remsock,(struct sockaddr *)¶m->sinsr,SASIZE(¶m->sinsr))) {
|
||||||
|
if(errno != EAGAIN) return (13);
|
||||||
|
}
|
||||||
|
memset(fds, 0, sizeof(fds));
|
||||||
|
fds[0].fd = param->remsock;
|
||||||
|
fds[0].events = POLLOUT;
|
||||||
|
if(so._poll(fds, 1, conf.timeouts[STRING_S]*1000) <= 0) {
|
||||||
|
return (13);
|
||||||
|
}
|
||||||
|
#ifndef _WIN32
|
||||||
|
#ifdef SO_ERROR
|
||||||
|
getsockopt(param->remsock, SOL_SOCKET, SO_ERROR, &ul, &us);
|
||||||
|
|
||||||
|
if (ul != 0) {
|
||||||
|
return (13);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
size = sizeof(param->sinsl);
|
size = sizeof(param->sinsl);
|
||||||
|
Loading…
Reference in New Issue
Block a user