Mercurial > hg > nginx-quic
annotate src/event/ngx_event_connect.c @ 136:da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 02 Oct 2003 05:39:37 +0000 |
parents | 049e78b1f852 |
children | 2a615b036870 |
rev | line source |
---|---|
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1 |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2 #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
|
3 #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
|
4 #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
|
5 #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
|
6 |
131
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
7 |
122
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
8 /* AF_INET only */ |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 |
124
842a78cebbb7
nginx-0.0.1-2003-08-01-18:56:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
122
diff
changeset
|
10 int 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
|
11 { |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
12 int rc, instance; |
122
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
13 time_t now; |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
14 ngx_err_t err; |
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
15 ngx_peer_t *peer; |
122
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
16 ngx_socket_t s; |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
17 ngx_event_t *rev, *wev; |
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
18 ngx_connection_t *c; |
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
19 struct sockaddr_in addr; |
122
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
20 |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
21 now = ngx_time(); |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
22 |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
23 /* ngx_lock_mutex(pc->peers->mutex); */ |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
24 |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
25 if (pc->peers->last_cached) { |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
26 |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
27 /* cached connection */ |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 |
131
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
29 pc->connection = pc->peers->cached[pc->peers->last_cached]; |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
30 pc->peers->last_cached--; |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
31 |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
32 /* ngx_unlock_mutex(pc->peers->mutex); */ |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
33 |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
34 pc->cached = 1; |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
35 return NGX_OK; |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
36 } |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
37 |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
38 pc->cached = 0; |
124
842a78cebbb7
nginx-0.0.1-2003-08-01-18:56:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
122
diff
changeset
|
39 pc->connection = NULL; |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
40 |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
41 peer = &pc->peers->peers[0]; |
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
42 |
120
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
43 if (pc->peers->number > 1) { |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
45 /* there are several peers */ |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
120
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
47 if (pc->tries == pc->peers->number) { |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
49 /* it's a first try - get a current peer */ |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
50 |
120
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
51 pc->cur_peer = pc->peers->current++; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
52 |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
53 if (pc->peers->current >= pc->peers->number) { |
120
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
54 pc->peers->current = 0; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 |
120
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
58 if (pc->peers->max_fails > 0) { |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
60 /* the peers support a fault tolerance */ |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
61 |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
62 for ( ;; ) { |
120
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
63 peer = &pc->peers->peers[pc->cur_peer]; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 |
120
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
65 if (peer->fails <= pc->peers->max_fails |
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
66 || (now - peer->accessed > pc->peers->fail_timeout)) |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 { |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 break; |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
70 |
120
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
71 pc->cur_peer++; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
72 |
120
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
73 if (pc->cur_peer >= pc->peers->number) { |
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
74 pc->cur_peer = 0; |
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 |
120
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
77 pc->tries--; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
78 |
120
b776ad95d96d
nginx-0.0.1-2003-07-21-20:24:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
79 if (pc->tries == 0) { |
122
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
80 /* ngx_unlock_mutex(pc->peers->mutex); */ |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
81 |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
82 return NGX_ERROR; |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
86 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
87 |
122
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
88 /* ngx_unlock_mutex(pc->peers->mutex); */ |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
89 |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
90 #if 0 |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
91 pc->addr_port_text = peer->addr_port_text; |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
92 #endif |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0); |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 if (s == -1) { |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
97 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
|
98 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
|
99 return NGX_ERROR; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
100 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
101 |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
102 if (pc->rcvbuf) { |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
103 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
104 (const void *) &pc->rcvbuf, sizeof(int)) == -1) { |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
105 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
|
106 "setsockopt(SO_RCVBUF) failed"); |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
107 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 if (ngx_close_socket(s) == -1) { |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
109 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
|
110 ngx_close_socket_n " failed"); |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
113 return NGX_ERROR; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 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
|
118 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
|
119 ngx_nonblocking_n " failed"); |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 if (ngx_close_socket(s) == -1) { |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
122 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
|
123 ngx_close_socket_n " failed"); |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
126 return NGX_ERROR; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
128 |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
129 #if (WIN32) |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
130 /* |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
131 * Winsock assignes a socket number divisible by 4 |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
132 * so to find a connection we divide a socket number by 4. |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
133 */ |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
134 |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
135 if (s % 4) { |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
136 ngx_log_error(NGX_LOG_EMERG, pc->log, 0, |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
137 ngx_socket_n |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
138 " created socket %d, not divisible by 4", s); |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
139 exit(1); |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
140 } |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
141 |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
142 c = &ngx_cycle->connections[s / 4]; |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
143 rev = &ngx_cycle->read_events[s / 4]; |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
144 wev = &ngx_cycle->write_events[s / 4]; |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
145 |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
146 #else |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
147 |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
148 c = &ngx_cycle->connections[s]; |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
149 rev = &ngx_cycle->read_events[s]; |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
150 wev = &ngx_cycle->write_events[s]; |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
151 |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
152 #endif |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 instance = rev->instance; |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 ngx_memzero(c, sizeof(ngx_connection_t)); |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 ngx_memzero(rev, sizeof(ngx_event_t)); |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 ngx_memzero(wev, sizeof(ngx_event_t)); |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 rev->index = wev->index = NGX_INVALID_INDEX; |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 rev->data = wev->data = c; |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 c->read = rev; |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 c->write = wev; |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 rev->instance = wev->instance = !instance; |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
167 rev->log = wev->log = c->log = pc->log; |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
168 c->fd = s; |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
169 |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
170 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
|
171 |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
172 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
|
173 if (ngx_add_conn(c) == NGX_ERROR) { |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
174 return NGX_ERROR; |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
175 } |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
176 } |
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
177 |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
178 addr.sin_family = AF_INET; |
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
179 addr.sin_addr.s_addr = peer->addr; |
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
180 addr.sin_port = htons(peer->port); |
122
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
181 |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
182 rc = connect(s, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)); |
122
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
183 |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
184 if (rc == -1) { |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
185 err = ngx_socket_errno; |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
186 if (err != NGX_EINPROGRESS) { |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
187 ngx_log_error(NGX_LOG_CRIT, pc->log, err, "connect() failed"); |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
188 |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
189 if (ngx_close_socket(s) == -1) { |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
190 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
191 ngx_close_socket_n " failed"); |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
192 } |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
193 |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
194 return NGX_CONNECT_ERROR; |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
195 } |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
196 } |
cd91e4a1ad0d
nginx-0.0.1-2003-07-23-17:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
197 |
136
da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
198 return NGX_OK; |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
199 } |
131
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
200 |
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
201 |
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
202 void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc) |
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
203 { |
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
204 return; |
049e78b1f852
nginx-0.0.1-2003-08-14-10:00:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
124
diff
changeset
|
205 } |