comparison src/event/ngx_event_connect.c @ 36:a39d1b793287 NGINX_0_1_18

nginx 0.1.18 *) Workaround: the default values of the devpoll_events and the devpoll_changes directives changed from 512 to 32 to be compatible with Solaris 10. *) Bugfix: the proxy_set_x_var and fastcgi_set_var directives were not inherited. *) Bugfix: in the redirect rewrite directive the arguments were concatenated with URI by the "&" rather than the "?". *) Bugfix: the lines without trailing ";" in the file being included by the ngx_http_geo_module were silently ignored. *) Feature: the ngx_http_stub_status_module. *) Bugfix: the unknown log format in the access_log directive caused the segmentation fault. *) Feature: the new "document_root" parameter of the fastcgi_params directive. *) Feature: the fastcgi_redirect_errors directive. *) Feature: the new "break" modifier of the "rewrite" directive allows to stop the rewrite/location cycle and sets the current configuration to the request.
author Igor Sysoev <http://sysoev.ru>
date Wed, 09 Feb 2005 00:00:00 +0300
parents da8c190bdaba
children b55cbf18157e
comparison
equal deleted inserted replaced
35:ef53675fe4a6 36:a39d1b793287
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 #include <ngx_event.h> 9 #include <ngx_event.h>
10 #include <ngx_event_connect.h> 10 #include <ngx_event_connect.h>
11 11
12 12
13 ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc) 13 #define NGX_RESOLVER_BUFSIZE 8192
14
15
16 ngx_int_t
17 ngx_event_connect_peer(ngx_peer_connection_t *pc)
14 { 18 {
15 int rc; 19 int rc;
16 ngx_uint_t instance; 20 ngx_uint_t instance;
17 u_int event; 21 u_int event;
18 time_t now; 22 time_t now;
272 /* Winsock returns WSAEWOULDBLOCK (NGX_EAGAIN) */ 276 /* Winsock returns WSAEWOULDBLOCK (NGX_EAGAIN) */
273 277
274 if (err != NGX_EINPROGRESS && err != NGX_EAGAIN) { 278 if (err != NGX_EINPROGRESS && err != NGX_EAGAIN) {
275 ngx_connection_error(c, err, "connect() failed"); 279 ngx_connection_error(c, err, "connect() failed");
276 280
277 if (ngx_close_socket(s) == -1) { 281 #if 0
278 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, 282 #undef sun
279 ngx_close_socket_n " failed"); 283 {
280 } 284 struct sockaddr_un *sun;
281 285
282 c->fd = (ngx_socket_t) -1; 286 sun = (struct sockaddr_un *) peer->sockaddr;
287
288 ngx_log_error(NGX_LOG_ALERT, pc->log, 0,
289 "\"%s\", f:%d, l:%uz",
290 sun->sun_path, sun->sun_family, peer->socklen);
291 }
292 #endif
283 293
284 return NGX_CONNECT_ERROR; 294 return NGX_CONNECT_ERROR;
285 } 295 }
286 } 296 }
287 297
288 if (ngx_add_conn) { 298 if (ngx_add_conn) {
289 if (rc == -1) { 299 if (rc == -1) {
300
290 /* NGX_EINPROGRESS */ 301 /* NGX_EINPROGRESS */
302
291 return NGX_AGAIN; 303 return NGX_AGAIN;
292 } 304 }
293 305
294 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pc->log, 0, "connected"); 306 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pc->log, 0, "connected");
295 307
306 /* aio, iocp */ 318 /* aio, iocp */
307 319
308 if (ngx_blocking(s) == -1) { 320 if (ngx_blocking(s) == -1) {
309 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, 321 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
310 ngx_blocking_n " failed"); 322 ngx_blocking_n " failed");
311
312 if (ngx_close_socket(s) == -1) {
313 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
314 ngx_close_socket_n " failed");
315 }
316
317 return NGX_ERROR; 323 return NGX_ERROR;
318 } 324 }
319 325
320 /* 326 /*
321 * FreeBSD aio allows to post operation on non-connected socket. 327 * FreeBSD's aio allows to post an operation on non-connected socket.
322 * NT does not support it. 328 * NT does not support it.
323 * 329 *
324 * TODO: check in Win32, etc. As workaround we can use NGX_ONESHOT_EVENT 330 * TODO: check in Win32, etc. As workaround we can use NGX_ONESHOT_EVENT
325 */ 331 */
326 332
328 wev->ready = 1; 334 wev->ready = 1;
329 335
330 return NGX_OK; 336 return NGX_OK;
331 } 337 }
332 338
333 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { /* kqueue */ 339 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
340
341 /* kqueue */
342
334 event = NGX_CLEAR_EVENT; 343 event = NGX_CLEAR_EVENT;
335 344
336 } else { /* select, poll, /dev/poll */ 345 } else {
346
347 /* select, poll, /dev/poll */
348
337 event = NGX_LEVEL_EVENT; 349 event = NGX_LEVEL_EVENT;
338 } 350 }
339 351
340 if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) { 352 if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) {
341 return NGX_ERROR; 353 return NGX_ERROR;
358 370
359 return NGX_OK; 371 return NGX_OK;
360 } 372 }
361 373
362 374
363 void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc) 375 void
376 ngx_event_connect_peer_failed(ngx_peer_connection_t *pc)
364 { 377 {
365 time_t now; 378 time_t now;
366 379
367 now = ngx_time(); 380 now = ngx_time();
368 381
378 if (pc->cur_peer >= pc->peers->number) { 391 if (pc->cur_peer >= pc->peers->number) {
379 pc->cur_peer = 0; 392 pc->cur_peer = 0;
380 } 393 }
381 394
382 pc->tries--; 395 pc->tries--;
383
384 return;
385 } 396 }