Deleted
Added
nxt_conn_accept.c (683:5c7dd85fabd5) | nxt_conn_accept.c (1457:af93c866b4f0) |
---|---|
1 2/* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) NGINX, Inc. 5 */ 6 7#include <nxt_main.h> 8 --- 10 unchanged lines hidden (view full) --- 19 20 21static nxt_conn_t *nxt_conn_accept_alloc(nxt_task_t *task, 22 nxt_listen_event_t *lev); 23static void nxt_conn_listen_handler(nxt_task_t *task, void *obj, 24 void *data); 25static nxt_conn_t *nxt_conn_accept_next(nxt_task_t *task, 26 nxt_listen_event_t *lev); | 1 2/* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) NGINX, Inc. 5 */ 6 7#include <nxt_main.h> 8 --- 10 unchanged lines hidden (view full) --- 19 20 21static nxt_conn_t *nxt_conn_accept_alloc(nxt_task_t *task, 22 nxt_listen_event_t *lev); 23static void nxt_conn_listen_handler(nxt_task_t *task, void *obj, 24 void *data); 25static nxt_conn_t *nxt_conn_accept_next(nxt_task_t *task, 26 nxt_listen_event_t *lev); |
27static nxt_int_t nxt_conn_accept_close_idle(nxt_task_t *task, | 27static void nxt_conn_accept_close_idle(nxt_task_t *task, |
28 nxt_listen_event_t *lev); | 28 nxt_listen_event_t *lev); |
29static void nxt_conn_accept_close_idle_handler(nxt_task_t *task, void *obj, 30 void *data); |
|
29static void nxt_conn_listen_event_error(nxt_task_t *task, void *obj, 30 void *data); 31static void nxt_conn_listen_timer_handler(nxt_task_t *task, void *obj, 32 void *data); 33 34 35nxt_listen_event_t * 36nxt_listen_event(nxt_task_t *task, nxt_listen_socket_t *ls) --- 188 unchanged lines hidden (view full) --- 225 226static nxt_conn_t * 227nxt_conn_accept_next(nxt_task_t *task, nxt_listen_event_t *lev) 228{ 229 nxt_conn_t *c; 230 231 lev->next = NULL; 232 | 31static void nxt_conn_listen_event_error(nxt_task_t *task, void *obj, 32 void *data); 33static void nxt_conn_listen_timer_handler(nxt_task_t *task, void *obj, 34 void *data); 35 36 37nxt_listen_event_t * 38nxt_listen_event(nxt_task_t *task, nxt_listen_socket_t *ls) --- 188 unchanged lines hidden (view full) --- 227 228static nxt_conn_t * 229nxt_conn_accept_next(nxt_task_t *task, nxt_listen_event_t *lev) 230{ 231 nxt_conn_t *c; 232 233 lev->next = NULL; 234 |
233 do { 234 c = nxt_conn_accept_alloc(task, lev); | 235 c = nxt_conn_accept_alloc(task, lev); |
235 | 236 |
236 if (nxt_fast_path(c != NULL)) { 237 return c; 238 } | 237 if (nxt_slow_path(c == NULL)) { 238 nxt_conn_accept_close_idle(task, lev); 239 } |
239 | 240 |
240 } while (nxt_conn_accept_close_idle(task, lev) == NXT_OK); | 241 return c; 242} |
241 | 243 |
242 nxt_alert(task, "no available connections, " 243 "new connections are not accepted within 1s"); | |
244 | 244 |
245 return NULL; | 245static void 246nxt_conn_accept_close_idle(nxt_task_t *task, nxt_listen_event_t *lev) 247{ 248 nxt_event_engine_t *engine; 249 250 engine = task->thread->engine; 251 252 nxt_work_queue_add(&engine->close_work_queue, 253 nxt_conn_accept_close_idle_handler, task, NULL, NULL); 254 255 nxt_timer_add(engine, &lev->timer, 100); 256 257 nxt_fd_event_disable_read(engine, &lev->socket); 258 259 nxt_alert(task, "new connections are not accepted within 100ms"); |
246} 247 248 | 260} 261 262 |
249static nxt_int_t 250nxt_conn_accept_close_idle(nxt_task_t *task, nxt_listen_event_t *lev) | 263static void 264nxt_conn_accept_close_idle_handler(nxt_task_t *task, void *obj, void *data) |
251{ | 265{ |
266 nxt_uint_t times; |
|
252 nxt_conn_t *c; 253 nxt_queue_t *idle; | 267 nxt_conn_t *c; 268 nxt_queue_t *idle; |
254 nxt_queue_link_t *link; | 269 nxt_queue_link_t *link, *next; |
255 nxt_event_engine_t *engine; 256 257 static nxt_log_moderation_t nxt_idle_close_log_moderation = { 258 NXT_LOG_INFO, 2, "idle connections closed", NXT_LOG_MODERATION 259 }; 260 | 270 nxt_event_engine_t *engine; 271 272 static nxt_log_moderation_t nxt_idle_close_log_moderation = { 273 NXT_LOG_INFO, 2, "idle connections closed", NXT_LOG_MODERATION 274 }; 275 |
276 times = 10; |
|
261 engine = task->thread->engine; | 277 engine = task->thread->engine; |
262 | |
263 idle = &engine->idle_connections; 264 265 for (link = nxt_queue_last(idle); 266 link != nxt_queue_head(idle); | 278 idle = &engine->idle_connections; 279 280 for (link = nxt_queue_last(idle); 281 link != nxt_queue_head(idle); |
267 link = nxt_queue_next(link)) | 282 link = next) |
268 { | 283 { |
284 next = nxt_queue_next(link); 285 |
|
269 c = nxt_queue_link_data(link, nxt_conn_t, link); 270 | 286 c = nxt_queue_link_data(link, nxt_conn_t, link); 287 |
288 nxt_debug(c->socket.task, "idle connection: %d rdy:%d", 289 c->socket.fd, c->socket.read_ready); 290 |
|
271 if (!c->socket.read_ready) { 272 nxt_log_moderate(&nxt_idle_close_log_moderation, NXT_LOG_INFO, 273 task->log, "no available connections, " 274 "close idle connection"); | 291 if (!c->socket.read_ready) { 292 nxt_log_moderate(&nxt_idle_close_log_moderation, NXT_LOG_INFO, 293 task->log, "no available connections, " 294 "close idle connection"); |
275 nxt_queue_remove(link); 276 nxt_conn_close(engine, c); | |
277 | 295 |
278 return NXT_OK; 279 } 280 } | 296 c->read_state->close_handler(c->socket.task, c, c->socket.data); |
281 | 297 |
282 nxt_timer_add(engine, &lev->timer, 1000); | 298 times--; |
283 | 299 |
284 nxt_fd_event_disable_read(engine, &lev->socket); 285 286 return NXT_DECLINED; | 300 if (times == 0) { 301 break; 302 } 303 } 304 } |
287} 288 289 290void 291nxt_conn_accept_error(nxt_task_t *task, nxt_listen_event_t *lev, 292 const char *accept_syscall, nxt_err_t err) 293{ 294 static nxt_log_moderation_t nxt_accept_log_moderation = { --- 13 unchanged lines hidden (view full) --- 308 task->log, "%s(%d) failed %E", 309 accept_syscall, lev->socket.fd, err); 310 return; 311 312 case EMFILE: 313 case ENFILE: 314 case ENOBUFS: 315 case ENOMEM: | 305} 306 307 308void 309nxt_conn_accept_error(nxt_task_t *task, nxt_listen_event_t *lev, 310 const char *accept_syscall, nxt_err_t err) 311{ 312 static nxt_log_moderation_t nxt_accept_log_moderation = { --- 13 unchanged lines hidden (view full) --- 326 task->log, "%s(%d) failed %E", 327 accept_syscall, lev->socket.fd, err); 328 return; 329 330 case EMFILE: 331 case ENFILE: 332 case ENOBUFS: 333 case ENOMEM: |
316 if (nxt_conn_accept_close_idle(task, lev) != NXT_OK) { 317 nxt_alert(task, "%s(%d) failed %E, " 318 "new connections are not accepted within 1s", 319 accept_syscall, lev->socket.fd, err); 320 } | 334 nxt_alert(task, "%s(%d) failed %E", 335 accept_syscall, lev->socket.fd, err); |
321 | 336 |
337 nxt_conn_accept_close_idle(task, lev); |
|
322 return; 323 324 default: 325 nxt_alert(task, "%s(%d) failed %E", 326 accept_syscall, lev->socket.fd, err); 327 return; 328 } 329} --- 37 unchanged lines hidden --- | 338 return; 339 340 default: 341 nxt_alert(task, "%s(%d) failed %E", 342 accept_syscall, lev->socket.fd, err); 343 return; 344 } 345} --- 37 unchanged lines hidden --- |