nxt_eventport_engine.c (62:5e1efcc7b740) nxt_eventport_engine.c (564:762f8c976ead)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

--- 95 unchanged lines hidden (view full) ---

104
105 engine->u.eventport.events = nxt_malloc(sizeof(port_event_t) * mevents);
106 if (engine->u.eventport.events == NULL) {
107 goto fail;
108 }
109
110 engine->u.eventport.fd = port_create();
111 if (engine->u.eventport.fd == -1) {
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

--- 95 unchanged lines hidden (view full) ---

104
105 engine->u.eventport.events = nxt_malloc(sizeof(port_event_t) * mevents);
106 if (engine->u.eventport.events == NULL) {
107 goto fail;
108 }
109
110 engine->u.eventport.fd = port_create();
111 if (engine->u.eventport.fd == -1) {
112 nxt_log(&engine->task, NXT_LOG_CRIT, "port_create() failed %E",
113 nxt_errno);
112 nxt_alert(&engine->task, "port_create() failed %E", nxt_errno);
114 goto fail;
115 }
116
117 nxt_debug(&engine->task, "port_create(): %d", engine->u.eventport.fd);
118
119 if (engine->signals != NULL) {
120 engine->u.eventport.signal_handler = engine->signals->handler;
121 }

--- 13 unchanged lines hidden (view full) ---

135{
136 int port;
137
138 port = engine->u.eventport.fd;
139
140 nxt_debug(&engine->task, "eventport %d free", port);
141
142 if (port != -1 && close(port) != 0) {
113 goto fail;
114 }
115
116 nxt_debug(&engine->task, "port_create(): %d", engine->u.eventport.fd);
117
118 if (engine->signals != NULL) {
119 engine->u.eventport.signal_handler = engine->signals->handler;
120 }

--- 13 unchanged lines hidden (view full) ---

134{
135 int port;
136
137 port = engine->u.eventport.fd;
138
139 nxt_debug(&engine->task, "eventport %d free", port);
140
141 if (port != -1 && close(port) != 0) {
143 nxt_log(&engine->task, NXT_LOG_CRIT, "eventport close(%d) failed %E",
144 port, nxt_errno);
142 nxt_alert(&engine->task, "eventport close(%d) failed %E",
143 port, nxt_errno);
145 }
146
147 nxt_free(engine->u.eventport.events);
148
149 nxt_memzero(&engine->u.eventport, sizeof(nxt_eventport_engine_t));
150}
151
152

--- 168 unchanged lines hidden (view full) ---

321
322 ret = port_associate(port, PORT_SOURCE_FD,
323 ev->fd, change->events, ev);
324
325 if (nxt_fast_path(ret == 0)) {
326 goto next;
327 }
328
144 }
145
146 nxt_free(engine->u.eventport.events);
147
148 nxt_memzero(&engine->u.eventport, sizeof(nxt_eventport_engine_t));
149}
150
151

--- 168 unchanged lines hidden (view full) ---

320
321 ret = port_associate(port, PORT_SOURCE_FD,
322 ev->fd, change->events, ev);
323
324 if (nxt_fast_path(ret == 0)) {
325 goto next;
326 }
327
329 nxt_log(ev->task, NXT_LOG_CRIT,
330 "port_associate(%d, %d, %d, %04XD) failed %E",
331 port, PORT_SOURCE_FD, ev->fd, change->events, nxt_errno);
328 nxt_alert(ev->task, "port_associate(%d, %d, %d, %04XD) failed %E",
329 port, PORT_SOURCE_FD, ev->fd, change->events, nxt_errno);
332
333 } else {
334 nxt_debug(ev->task, "port_dissociate(%d): fd:%d", port, ev->fd);
335
336 ret = port_dissociate(port, PORT_SOURCE_FD, ev->fd);
337
338 if (nxt_fast_path(ret == 0)) {
339 goto next;
340 }
341
330
331 } else {
332 nxt_debug(ev->task, "port_dissociate(%d): fd:%d", port, ev->fd);
333
334 ret = port_dissociate(port, PORT_SOURCE_FD, ev->fd);
335
336 if (nxt_fast_path(ret == 0)) {
337 goto next;
338 }
339
342 nxt_log(ev->task, NXT_LOG_CRIT,
343 "port_dissociate(%d, %d, %d) failed %E",
344 port, PORT_SOURCE_FD, ev->fd, nxt_errno);
340 nxt_alert(ev->task, "port_dissociate(%d, %d, %d) failed %E",
341 port, PORT_SOURCE_FD, ev->fd, nxt_errno);
345 }
346
347 nxt_work_queue_add(&engine->fast_work_queue,
348 nxt_eventport_error_handler,
349 ev->task, ev, ev->data);
350
351 retval = NXT_ERROR;
352

--- 87 unchanged lines hidden (view full) ---

440{
441 int port;
442
443 port = engine->u.eventport.fd;
444
445 nxt_debug(&engine->task, "port_send(%d, %ui)", port, signo);
446
447 if (port_send(port, signo, NULL) != 0) {
342 }
343
344 nxt_work_queue_add(&engine->fast_work_queue,
345 nxt_eventport_error_handler,
346 ev->task, ev, ev->data);
347
348 retval = NXT_ERROR;
349

--- 87 unchanged lines hidden (view full) ---

437{
438 int port;
439
440 port = engine->u.eventport.fd;
441
442 nxt_debug(&engine->task, "port_send(%d, %ui)", port, signo);
443
444 if (port_send(port, signo, NULL) != 0) {
448 nxt_log(&engine->task, NXT_LOG_CRIT, "port_send(%d) failed %E",
449 port, nxt_errno);
445 nxt_alert(&engine->task, "port_send(%d) failed %E", port, nxt_errno);
450 }
451}
452
453
454static void
455nxt_eventport_poll(nxt_event_engine_t *engine, nxt_msec_t timeout)
456{
457 int n, events, signo;

--- 48 unchanged lines hidden (view full) ---

506 */
507 err = (n < 0) ? nxt_errno : 0;
508
509 nxt_thread_time_update(engine->task.thread);
510
511 if (n == -1) {
512 if (err == NXT_ETIME || err == NXT_EINTR) {
513 if (nevents != 0) {
446 }
447}
448
449
450static void
451nxt_eventport_poll(nxt_event_engine_t *engine, nxt_msec_t timeout)
452{
453 int n, events, signo;

--- 48 unchanged lines hidden (view full) ---

502 */
503 err = (n < 0) ? nxt_errno : 0;
504
505 nxt_thread_time_update(engine->task.thread);
506
507 if (n == -1) {
508 if (err == NXT_ETIME || err == NXT_EINTR) {
509 if (nevents != 0) {
514 nxt_log(&engine->task, NXT_LOG_CRIT,
515 "port_getn(%d) failed %E, events:%ud",
516 engine->u.eventport.fd, err, nevents);
510 nxt_alert(&engine->task, "port_getn(%d) failed %E, events:%ud",
511 engine->u.eventport.fd, err, nevents);
517 }
518 }
519
520 if (err != NXT_ETIME) {
512 }
513 }
514
515 if (err != NXT_ETIME) {
521 level = (err == NXT_EINTR) ? NXT_LOG_INFO : NXT_LOG_CRIT;
516 level = (err == NXT_EINTR) ? NXT_LOG_INFO : NXT_LOG_ALERT;
522
523 nxt_log(&engine->task, level, "port_getn(%d) failed %E",
524 engine->u.eventport.fd, err);
525
526 if (err != NXT_EINTR) {
527 return;
528 }
529 }

--- 10 unchanged lines hidden (view full) ---

540 case PORT_SOURCE_FD:
541 ev = event->portev_user;
542 events = event->portev_events;
543
544 nxt_debug(ev->task, "eventport: fd:%d ev:%04Xd u:%p rd:%d wr:%d",
545 event->portev_object, events, ev, ev->read, ev->write);
546
547 if (nxt_slow_path(events & (POLLERR | POLLHUP | POLLNVAL)) != 0) {
517
518 nxt_log(&engine->task, level, "port_getn(%d) failed %E",
519 engine->u.eventport.fd, err);
520
521 if (err != NXT_EINTR) {
522 return;
523 }
524 }

--- 10 unchanged lines hidden (view full) ---

535 case PORT_SOURCE_FD:
536 ev = event->portev_user;
537 events = event->portev_events;
538
539 nxt_debug(ev->task, "eventport: fd:%d ev:%04Xd u:%p rd:%d wr:%d",
540 event->portev_object, events, ev, ev->read, ev->write);
541
542 if (nxt_slow_path(events & (POLLERR | POLLHUP | POLLNVAL)) != 0) {
548 nxt_log(ev->task, NXT_LOG_CRIT,
549 "port_getn(%d) error fd:%d events:%04Xud",
550 engine->u.eventport.fd, ev->fd, events);
543 nxt_alert(ev->task, "port_getn(%d) error fd:%d events:%04Xud",
544 engine->u.eventport.fd, ev->fd, events);
551
552 nxt_work_queue_add(&engine->fast_work_queue,
553 nxt_eventport_error_handler,
554 ev->task, ev, ev->data);
555 continue;
556 }
557
558 if (events & POLLIN) {

--- 44 unchanged lines hidden (view full) ---

603 : engine->u.eventport.signal_handler;
604
605 nxt_work_queue_add(&engine->fast_work_queue, handler,
606 &engine->task, (void *) (uintptr_t) signo, NULL);
607
608 break;
609
610 default:
545
546 nxt_work_queue_add(&engine->fast_work_queue,
547 nxt_eventport_error_handler,
548 ev->task, ev, ev->data);
549 continue;
550 }
551
552 if (events & POLLIN) {

--- 44 unchanged lines hidden (view full) ---

597 : engine->u.eventport.signal_handler;
598
599 nxt_work_queue_add(&engine->fast_work_queue, handler,
600 &engine->task, (void *) (uintptr_t) signo, NULL);
601
602 break;
603
604 default:
611 nxt_log(&engine->task, NXT_LOG_CRIT,
612 "unexpected port_getn(%d) event: ev:%d src:%d obj:%p u:%p",
613 engine->u.eventport.fd, event->portev_events,
614 event->portev_source, event->portev_object,
615 event->portev_user);
605 nxt_alert(&engine->task,
606 "unexpected port_getn(%d) event: "
607 "ev:%d src:%d obj:%p u:%p",
608 engine->u.eventport.fd, event->portev_events,
609 event->portev_source, event->portev_object,
610 event->portev_user);
616 }
617 }
618}
611 }
612 }
613}