Lines 243-250
static int nb_connect(jk_sock_t sd, jk_sockaddr_t *addr, jk_sockaddr_t *source,
Link Here
|
243 |
return 0; |
243 |
return 0; |
244 |
} |
244 |
} |
245 |
|
245 |
|
|
|
246 |
#elif !defined(NETWARE) && defined(HAVE_POLL_H) |
247 |
/* POSIX implementation using poll(2) */ |
248 |
/** Non-blocking socket connect |
249 |
* @param sd socket to connect |
250 |
* @param addr address to connect to |
251 |
* @param source optional source address |
252 |
* @param timeout connect timeout in seconds |
253 |
* (<=0: no timeout=blocking) |
254 |
* @param l logger |
255 |
* @return -1: some kind of error occured |
256 |
* 0: success |
257 |
*/ |
258 |
static int nb_connect(jk_sock_t sd, jk_sockaddr_t *addr, jk_sockaddr_t *source, |
259 |
int timeout, jk_logger_t *l) { |
260 |
int rc = 0; |
261 |
char buf[64]; |
262 |
|
263 |
JK_TRACE_ENTER(l); |
264 |
|
265 |
if (source != NULL) { |
266 |
if (bind(sd, (const struct sockaddr *)&source->sa.sin, source->salen)) { |
267 |
JK_GET_SOCKET_ERRNO(); |
268 |
jk_log(l, JK_LOG_ERROR, |
269 |
"error during source bind on socket %d [%s] (errno=%d)", sd, |
270 |
jk_dump_hinfo(source, buf, sizeof(buf)), errno); |
271 |
} |
272 |
} |
273 |
if (timeout > 0) { |
274 |
if (sononblock(sd)) { |
275 |
JK_TRACE_EXIT(l); |
276 |
return -1; |
277 |
} |
278 |
} |
279 |
do { |
280 |
rc = connect(sd, (const struct sockaddr *)&addr->sa.sin, addr->salen); |
281 |
} while (rc == -1 && errno == EINTR); |
282 |
|
283 |
if ((rc == -1) && (errno == EINPROGRESS || errno == EALREADY) |
284 |
&& (timeout > 0)) { |
285 |
struct pollfd pfd; |
286 |
socklen_t rclen = (socklen_t)sizeof(rc); |
287 |
pfd.fd = sd; |
288 |
pfd.events = POLLOUT; |
289 |
rc = poll(&pfd, 1, timeout * 1000); |
290 |
if (rc <= 0) { |
291 |
/* Save errno */ |
292 |
int err = errno; |
293 |
soblock(sd); |
294 |
errno = err; |
295 |
JK_TRACE_EXIT(l); |
296 |
return -1; |
297 |
} |
298 |
rc = 0; |
299 |
#ifdef SO_ERROR |
300 |
if (getsockopt(sd, SOL_SOCKET, SO_ERROR, |
301 |
(char *)&rc, &rclen) < 0 || rc) { |
302 |
if (rc) |
303 |
errno = rc; |
304 |
rc = -1; |
305 |
} |
306 |
#endif |
307 |
} |
308 |
soblock(sd); |
309 |
JK_TRACE_EXIT(l); |
310 |
return rc; |
311 |
} |
312 |
|
246 |
#elif !defined(NETWARE) |
313 |
#elif !defined(NETWARE) |
247 |
/* POSIX implementation */ |
314 |
/* POSIX implementation using select(2) */ |
248 |
/** Non-blocking socket connect |
315 |
/** Non-blocking socket connect |
249 |
* @param sd socket to connect |
316 |
* @param sd socket to connect |
250 |
* @param addr address to connect to |
317 |
* @param addr address to connect to |
251 |
- |
|
|