comparison src/event/ngx_event_connectex.c @ 187:5a9bbe99008b

nginx-0.0.1-2003-11-17-19:15:03 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 17 Nov 2003 16:15:03 +0000
parents c1f3a3c7c5db
children da8c5707af39
comparison
equal deleted inserted replaced
186:c1f3a3c7c5db 187:5a9bbe99008b
12 static ngx_connection_t pending_connects[NGX_MAX_PENDING_CONN]; 12 static ngx_connection_t pending_connects[NGX_MAX_PENDING_CONN];
13 13
14 static HANDLE pending_connect_event; 14 static HANDLE pending_connect_event;
15 15
16 __declspec(thread) int nevents = 0; 16 __declspec(thread) int nevents = 0;
17 __declspec(thread) WSAEVENT events[WSA_MAXIMUM_WAIT_EVENTS]; 17 __declspec(thread) WSAEVENT events[WSA_MAXIMUM_WAIT_EVENTS + 1];
18 __declspec(thread) ngx_connection_t *conn[WSA_MAXIMUM_WAIT_EVENTS]; 18 __declspec(thread) ngx_connection_t *conn[WSA_MAXIMUM_WAIT_EVENTS + 1];
19 19
20 20
21 21
22 int ngx_iocp_wait_connect(ngx_connection_t *c) 22 int ngx_iocp_wait_connect(ngx_connection_t *c)
23 { 23 {
119 nevents = 1; 119 nevents = 1;
120 events[0] = pending_connect_event; 120 events[0] = pending_connect_event;
121 conn[0] = NULL; 121 conn[0] = NULL;
122 122
123 for ( ;; ) { 123 for ( ;; ) {
124 offset = (nevents == WSA_MAXIMUM_WAIT_EVENTS) ? 1: 0; 124 offset = (nevents == WSA_MAXIMUM_WAIT_EVENTS + 1) ? 1: 0;
125 timeout = (nevents == 1 && !first) ? 60000: INFINITE; 125 timeout = (nevents == 1 && !first) ? 60000: INFINITE;
126 126
127 n = WSAWaitForMultipleEvents(nevents - offset, events[offset], 127 n = WSAWaitForMultipleEvents(nevents - offset, events[offset],
128 0, timeout, 0); 128 0, timeout, 0);
129 if (n == WAIT_FAILED) { 129 if (n == WAIT_FAILED) {
131 "WSAWaitForMultipleEvents() failed"); 131 "WSAWaitForMultipleEvents() failed");
132 continue; 132 continue;
133 } 133 }
134 134
135 if (n == WAIT_TIMEOUT) { 135 if (n == WAIT_TIMEOUT) {
136 if (nevents == 1 && !main) { 136 if (nevents == 2 && !main) {
137 ExitThread(0); 137 ExitThread(0);
138 } 138 }
139 139
140 ngx_log_error(NGX_LOG_ALERT, log, 0, 140 ngx_log_error(NGX_LOG_ALERT, log, 0,
141 "WSAWaitForMultipleEvents() " 141 "WSAWaitForMultipleEvents() "
143 continue; 143 continue;
144 } 144 }
145 145
146 n -= WSA_WAIT_EVENT_0; 146 n -= WSA_WAIT_EVENT_0;
147 147
148 if (n == 0) { 148 if (events[n] == NULL) {
149 149
150 /* the first event is pending_connect_event */ 150 /* the pending_connect_event */
151 151
152 if (nevents == WSA_MAXIMUM_WAIT_EVENTS) { 152 if (nevents == WSA_MAXIMUM_WAIT_EVENTS) {
153 ngx_iocp_new_thread(0); 153 ngx_iocp_new_thread(0);
154 } else { 154 } else {
155 ngx_iocp_new_connect(); 155 ngx_iocp_new_connect();