Mercurial > hg > nginx-quic
annotate src/event/ngx_event_connect.c @ 5749:a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
The ngx_open_dir() function changed to restore name passed to it. This
fixes removing destination directory in dav module, as caught by dav.t.
The ngx_close_dir() function introduced to properly convert errors, as
FindClose() returns 0 on error.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 05 Jul 2014 23:29:47 +0400 |
parents | 957d734362ed |
children | 3377f9459e99 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
6 |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
8 #include <ngx_config.h> |
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
9 #include <ngx_core.h> |
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
10 #include <ngx_event.h> |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 #include <ngx_event_connect.h> |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
131
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
13 |
487 | 14 ngx_int_t |
15 ngx_event_connect_peer(ngx_peer_connection_t *pc) | |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 { |
543 | 17 int rc; |
1470 | 18 ngx_int_t event; |
543 | 19 ngx_err_t err; |
884 | 20 ngx_uint_t level; |
543 | 21 ngx_socket_t s; |
22 ngx_event_t *rev, *wev; | |
23 ngx_connection_t *c; | |
122
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
24 |
884 | 25 rc = pc->get(pc, pc->data); |
26 if (rc != NGX_OK) { | |
27 return rc; | |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
28 } |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
29 |
884 | 30 s = ngx_socket(pc->sockaddr->sa_family, SOCK_STREAM, 0); |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 |
884 | 32 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, 0, "socket %d", s); |
509 | 33 |
5360
3d2d3e1cf427
Win32: MinGW GCC compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5141
diff
changeset
|
34 if (s == (ngx_socket_t) -1) { |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
35 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 ngx_socket_n " failed"); |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
37 return NGX_ERROR; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 |
323
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
40 |
543 | 41 c = ngx_get_connection(s, pc->log); |
323
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
42 |
543 | 43 if (c == NULL) { |
323
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
44 if (ngx_close_socket(s) == -1) { |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
45 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
46 ngx_close_socket_n "failed"); |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
47 } |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
48 |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
49 return NGX_ERROR; |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
50 } |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
309
diff
changeset
|
51 |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
52 if (pc->rcvbuf) { |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, |
563 | 54 (const void *) &pc->rcvbuf, sizeof(int)) == -1) |
55 { | |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
56 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 "setsockopt(SO_RCVBUF) failed"); |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
58 goto failed; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
61 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
62 if (ngx_nonblocking(s) == -1) { |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
63 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 ngx_nonblocking_n " failed"); |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
65 |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
66 goto failed; |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
67 } |
543 | 68 |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
69 if (pc->local) { |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
70 if (bind(s, pc->local->sockaddr, pc->local->socklen) == -1) { |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
71 ngx_log_error(NGX_LOG_CRIT, pc->log, ngx_socket_errno, |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
72 "bind(%V) failed", &pc->local->name); |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
73 |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
74 goto failed; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
77 |
543 | 78 c->recv = ngx_recv; |
79 c->send = ngx_send; | |
577 | 80 c->recv_chain = ngx_recv_chain; |
543 | 81 c->send_chain = ngx_send_chain; |
483 | 82 |
1397
6c25a49e548a
upstream sendfile bit was overridden by r->connection->sendfile
Igor Sysoev <igor@sysoev.ru>
parents:
884
diff
changeset
|
83 c->sendfile = 1; |
6c25a49e548a
upstream sendfile bit was overridden by r->connection->sendfile
Igor Sysoev <igor@sysoev.ru>
parents:
884
diff
changeset
|
84 |
543 | 85 c->log_error = pc->log_error; |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
86 |
5141
87faa6b818bc
Event connect: don't penalize AF_INET6 connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4421
diff
changeset
|
87 if (pc->sockaddr->sa_family == AF_UNIX) { |
543 | 88 c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; |
89 c->tcp_nodelay = NGX_TCP_NODELAY_DISABLED; | |
583 | 90 |
91 #if (NGX_SOLARIS) | |
92 /* Solaris's sendfilev() supports AF_NCA, AF_INET, and AF_INET6 */ | |
93 c->sendfile = 0; | |
94 #endif | |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
95 } |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
96 |
561 | 97 rev = c->read; |
98 wev = c->write; | |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
189
diff
changeset
|
100 rev->log = pc->log; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
189
diff
changeset
|
101 wev->log = pc->log; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
189
diff
changeset
|
102 |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
103 pc->connection = c; |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
104 |
561 | 105 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
106 |
377
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
107 #if (NGX_THREADS) |
3365 | 108 |
109 /* TODO: lock event when call completion handler */ | |
110 | |
377
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
111 rev->lock = pc->lock; |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
112 wev->lock = pc->lock; |
380
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
113 rev->own_lock = &c->lock; |
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
114 wev->own_lock = &c->lock; |
3365 | 115 |
377
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
116 #endif |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
117 |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
118 if (ngx_add_conn) { |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
119 if (ngx_add_conn(c) == NGX_ERROR) { |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
120 goto failed; |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
121 } |
577 | 122 } |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
123 |
543 | 124 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pc->log, 0, |
5600
957d734362ed
Fixed format specifier in logging of "c->number".
Sergey Kandaurov <pluknet@nginx.com>
parents:
5360
diff
changeset
|
125 "connect to %V, fd:%d #%uA", pc->name, s, c->number); |
137
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
126 |
884 | 127 rc = connect(s, pc->sockaddr, pc->socklen); |
122
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
128 |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
129 if (rc == -1) { |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
130 err = ngx_socket_errno; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
169
diff
changeset
|
131 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
169
diff
changeset
|
132 |
2117
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
133 if (err != NGX_EINPROGRESS |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
134 #if (NGX_WIN32) |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
135 /* Winsock returns WSAEWOULDBLOCK (NGX_EAGAIN) */ |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
136 && err != NGX_EAGAIN |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
137 #endif |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
138 ) |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
139 { |
1869
192443881e51
add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents:
1470
diff
changeset
|
140 if (err == NGX_ECONNREFUSED |
2117
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
141 #if (NGX_LINUX) |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
142 /* |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
143 * Linux returns EAGAIN instead of ECONNREFUSED |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
144 * for unix sockets if listen queue is full |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
145 */ |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
146 || err == NGX_EAGAIN |
9d62abd76ea5
handle connect()'s EAGAIN on Linux
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
147 #endif |
2540 | 148 || err == NGX_ECONNRESET |
1869
192443881e51
add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents:
1470
diff
changeset
|
149 || err == NGX_ENETDOWN |
192443881e51
add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents:
1470
diff
changeset
|
150 || err == NGX_ENETUNREACH |
192443881e51
add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents:
1470
diff
changeset
|
151 || err == NGX_EHOSTDOWN |
192443881e51
add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents:
1470
diff
changeset
|
152 || err == NGX_EHOSTUNREACH) |
192443881e51
add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents:
1470
diff
changeset
|
153 { |
541 | 154 level = NGX_LOG_ERR; |
1869
192443881e51
add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents:
1470
diff
changeset
|
155 |
541 | 156 } else { |
157 level = NGX_LOG_CRIT; | |
158 } | |
487 | 159 |
541 | 160 ngx_log_error(level, c->log, err, "connect() to %V failed", |
884 | 161 pc->name); |
139
54307053f185
nginx-0.0.1-2003-10-07-19:30:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
137
diff
changeset
|
162 |
4421
fbae1a82de8b
Fixed error handling in ngx_event_connect_peer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
163 ngx_close_connection(c); |
fbae1a82de8b
Fixed error handling in ngx_event_connect_peer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
164 pc->connection = NULL; |
fbae1a82de8b
Fixed error handling in ngx_event_connect_peer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
165 |
543 | 166 return NGX_DECLINED; |
122
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
167 } |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
168 } |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
169 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
170 if (ngx_add_conn) { |
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
171 if (rc == -1) { |
487 | 172 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
173 /* NGX_EINPROGRESS */ |
487 | 174 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
175 return NGX_AGAIN; |
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
176 } |
577 | 177 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
178 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pc->log, 0, "connected"); |
483 | 179 |
180 wev->ready = 1; | |
181 | |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
182 return NGX_OK; |
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
183 } |
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
323
diff
changeset
|
184 |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
162
diff
changeset
|
185 if (ngx_event_flags & NGX_USE_AIO_EVENT) { |
167
8aef3c72e5da
nginx-0.0.1-2003-10-30-19:51:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
186 |
455 | 187 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, ngx_socket_errno, |
188 "connect(): %d", rc); | |
189 | |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
162
diff
changeset
|
190 /* aio, iocp */ |
167
8aef3c72e5da
nginx-0.0.1-2003-10-30-19:51:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
191 |
8aef3c72e5da
nginx-0.0.1-2003-10-30-19:51:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
192 if (ngx_blocking(s) == -1) { |
8aef3c72e5da
nginx-0.0.1-2003-10-30-19:51:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
193 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, |
8aef3c72e5da
nginx-0.0.1-2003-10-30-19:51:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
194 ngx_blocking_n " failed"); |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
195 goto failed; |
167
8aef3c72e5da
nginx-0.0.1-2003-10-30-19:51:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
196 } |
8aef3c72e5da
nginx-0.0.1-2003-10-30-19:51:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
197 |
8aef3c72e5da
nginx-0.0.1-2003-10-30-19:51:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
198 /* |
487 | 199 * FreeBSD's aio allows to post an operation on non-connected socket. |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
169
diff
changeset
|
200 * NT does not support it. |
577 | 201 * |
169
edf29bb717da
nginx-0.0.1-2003-10-31-19:05:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
168
diff
changeset
|
202 * TODO: check in Win32, etc. As workaround we can use NGX_ONESHOT_EVENT |
167
8aef3c72e5da
nginx-0.0.1-2003-10-30-19:51:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
203 */ |
577 | 204 |
166
389d7ee9fa60
nginx-0.0.1-2003-10-30-11:51:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
205 rev->ready = 1; |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
162
diff
changeset
|
206 wev->ready = 1; |
166
389d7ee9fa60
nginx-0.0.1-2003-10-30-11:51:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
207 |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
162
diff
changeset
|
208 return NGX_OK; |
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
162
diff
changeset
|
209 } |
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
162
diff
changeset
|
210 |
487 | 211 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { |
212 | |
213 /* kqueue */ | |
214 | |
137
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
215 event = NGX_CLEAR_EVENT; |
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
216 |
487 | 217 } else { |
218 | |
219 /* select, poll, /dev/poll */ | |
220 | |
137
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
221 event = NGX_LEVEL_EVENT; |
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
222 } |
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
223 |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
161
diff
changeset
|
224 if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) { |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
225 goto failed; |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
161
diff
changeset
|
226 } |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
161
diff
changeset
|
227 |
137
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
228 if (rc == -1) { |
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
229 |
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
230 /* NGX_EINPROGRESS */ |
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
231 |
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
232 if (ngx_add_event(wev, NGX_WRITE_EVENT, event) != NGX_OK) { |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
233 goto failed; |
137
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
234 } |
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
235 |
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
236 return NGX_AGAIN; |
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
237 } |
2a615b036870
nginx-0.0.1-2003-10-03-19:50:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
238 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
239 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pc->log, 0, "connected"); |
189
c966c09be66b
nginx-0.0.1-2003-11-18-19:49:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
240 |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
241 wev->ready = 1; |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
242 |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
243 return NGX_OK; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
244 |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
245 failed: |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
246 |
4421
fbae1a82de8b
Fixed error handling in ngx_event_connect_peer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
247 ngx_close_connection(c); |
fbae1a82de8b
Fixed error handling in ngx_event_connect_peer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
248 pc->connection = NULL; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
249 |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
2540
diff
changeset
|
250 return NGX_ERROR; |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
251 } |
131
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
252 |
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
253 |
884 | 254 ngx_int_t |
255 ngx_event_get_peer(ngx_peer_connection_t *pc, void *data) | |
131
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
256 { |
884 | 257 return NGX_OK; |
131
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
258 } |