mirror of
https://github.com/3proxy/3proxy.git
synced 2025-02-23 18:45: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)){
|
||||
struct pollfd fds[1];
|
||||
#ifdef _WIN32
|
||||
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);
|
||||
#else
|
||||
socklen_t us = sizeof(ul);
|
||||
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
|
||||
}
|
||||
size = sizeof(param->sinsl);
|
||||
|
Loading…
Reference in New Issue
Block a user