implement timeout on connect()

STRING_S timeout is used (15 sec by default)
This commit is contained in:
z3APA3A 2016-12-22 17:11:44 +03:00
parent c5f8a8e139
commit d1d86ed9b3

View File

@ -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 *)&param->sinsr,SASIZE(&param->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 *)&param->sinsr,SASIZE(&param->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);