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

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

117 engine->u.pollset.events = nxt_malloc(sizeof(struct pollfd) * mevents);
118 if (engine->u.pollset.events == NULL) {
119 goto fail;
120 }
121
122 engine->u.pollset.ps = pollset_create(-1);
123
124 if (engine->u.pollset.ps == -1) {
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

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

117 engine->u.pollset.events = nxt_malloc(sizeof(struct pollfd) * mevents);
118 if (engine->u.pollset.events == NULL) {
119 goto fail;
120 }
121
122 engine->u.pollset.ps = pollset_create(-1);
123
124 if (engine->u.pollset.ps == -1) {
125 nxt_log(&engine->task, NXT_LOG_CRIT, "pollset_create() failed %E",
126 nxt_errno);
125 nxt_alert(&engine->task, "pollset_create() failed %E", nxt_errno);
127 goto fail;
128 }
129
130 nxt_debug(&engine->task, "pollset_create(): %d", engine->u.pollset.ps);
131
132 return NXT_OK;
133
134fail:

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

144{
145 pollset_t ps;
146
147 ps = engine->u.pollset.ps;
148
149 nxt_debug(&engine->task, "pollset %d free", ps);
150
151 if (ps != -1 && pollset_destroy(ps) != 0) {
126 goto fail;
127 }
128
129 nxt_debug(&engine->task, "pollset_create(): %d", engine->u.pollset.ps);
130
131 return NXT_OK;
132
133fail:

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

143{
144 pollset_t ps;
145
146 ps = engine->u.pollset.ps;
147
148 nxt_debug(&engine->task, "pollset %d free", ps);
149
150 if (ps != -1 && pollset_destroy(ps) != 0) {
152 nxt_log(&engine->task, NXT_LOG_CRIT, "pollset_destroy(%d) failed %E",
153 ps, nxt_errno);
151 nxt_alert(&engine->task, "pollset_destroy(%d) failed %E",
152 ps, nxt_errno);
154 }
155
156 nxt_free(engine->u.pollset.events);
157 nxt_free(engine->u.pollset.write_changes);
158 nxt_free(engine->u.pollset.changes);
159 nxt_fd_event_hash_destroy(&engine->u.pollset.fd_hash);
160
161 nxt_memzero(&engine->u.pollset, sizeof(nxt_pollset_engine_t));

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

496 engine->u.pollset.ps, fd, n);
497
498 if (n == 0) {
499 /* The file descriptor is not in the pollset. */
500 return;
501 }
502
503 if (n == -1) {
153 }
154
155 nxt_free(engine->u.pollset.events);
156 nxt_free(engine->u.pollset.write_changes);
157 nxt_free(engine->u.pollset.changes);
158 nxt_fd_event_hash_destroy(&engine->u.pollset.fd_hash);
159
160 nxt_memzero(&engine->u.pollset, sizeof(nxt_pollset_engine_t));

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

495 engine->u.pollset.ps, fd, n);
496
497 if (n == 0) {
498 /* The file descriptor is not in the pollset. */
499 return;
500 }
501
502 if (n == -1) {
504 nxt_log(&engine->task, NXT_LOG_CRIT, "pollset_query(%d, %d) failed %E",
505 engine->u.pollset.ps, fd, nxt_errno);
503 nxt_alert(&engine->task, "pollset_query(%d, %d) failed %E",
504 engine->u.pollset.ps, fd, nxt_errno);
506 /* Fall through. */
507 }
508
509 /* n == 1: The file descriptor is in the pollset. */
510
511 nxt_debug(&engine->task, "pollset %d remove fd:%d",
512 engine->u.pollset.ps, fd);
513

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

531 nxt_set_errno(0);
532
533 n = pollset_ctl(ps, ctl, n);
534
535 if (nxt_fast_path(n == 0)) {
536 return NXT_OK;
537 }
538
505 /* Fall through. */
506 }
507
508 /* n == 1: The file descriptor is in the pollset. */
509
510 nxt_debug(&engine->task, "pollset %d remove fd:%d",
511 engine->u.pollset.ps, fd);
512

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

530 nxt_set_errno(0);
531
532 n = pollset_ctl(ps, ctl, n);
533
534 if (nxt_fast_path(n == 0)) {
535 return NXT_OK;
536 }
537
539 nxt_log(&engine->task, NXT_LOG_CRIT, "pollset_ctl(%d) failed: %d %E",
540 ps, n, nxt_errno);
538 nxt_alert(&engine->task, "pollset_ctl(%d) failed: %d %E", ps, n, nxt_errno);
541
542 return NXT_ERROR;
543}
544
545
546static void
547nxt_pollset_poll(nxt_event_engine_t *engine, nxt_msec_t timeout)
548{

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

570 err = (nevents == -1) ? nxt_errno : 0;
571
572 nxt_thread_time_update(engine->task.thread);
573
574 nxt_debug(&engine->task, "pollset_poll(%d): %d",
575 engine->u.pollset.ps, nevents);
576
577 if (nevents == -1) {
539
540 return NXT_ERROR;
541}
542
543
544static void
545nxt_pollset_poll(nxt_event_engine_t *engine, nxt_msec_t timeout)
546{

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

568 err = (nevents == -1) ? nxt_errno : 0;
569
570 nxt_thread_time_update(engine->task.thread);
571
572 nxt_debug(&engine->task, "pollset_poll(%d): %d",
573 engine->u.pollset.ps, nevents);
574
575 if (nevents == -1) {
578 level = (err == NXT_EINTR) ? NXT_LOG_INFO : NXT_LOG_CRIT;
576 level = (err == NXT_EINTR) ? NXT_LOG_INFO : NXT_LOG_ALERT;
579
580 nxt_log(&engine->task, level, "pollset_poll(%d) failed %E",
581 engine->u.pollset.ps, err);
582
583 return;
584 }
585
586 for (i = 0; i < nevents; i++) {
587
588 pfd = &engine->u.pollset.events[i];
589 fd = pfd->fd;
590 events = pfd->revents;
591
592 ev = nxt_fd_event_hash_get(&engine->task, &engine->u.pollset.fd_hash,
593 fd);
594
595 if (nxt_slow_path(ev == NULL)) {
577
578 nxt_log(&engine->task, level, "pollset_poll(%d) failed %E",
579 engine->u.pollset.ps, err);
580
581 return;
582 }
583
584 for (i = 0; i < nevents; i++) {
585
586 pfd = &engine->u.pollset.events[i];
587 fd = pfd->fd;
588 events = pfd->revents;
589
590 ev = nxt_fd_event_hash_get(&engine->task, &engine->u.pollset.fd_hash,
591 fd);
592
593 if (nxt_slow_path(ev == NULL)) {
596 nxt_log(&engine->task, NXT_LOG_CRIT,
597 "pollset_poll(%d) returned invalid "
598 "fd:%d ev:%04Xd rev:%04uXi",
599 engine->u.pollset.ps, fd, pfd->events, events);
594 nxt_alert(&engine->task,
595 "pollset_poll(%d) returned invalid "
596 "fd:%d ev:%04Xd rev:%04uXi",
597 engine->u.pollset.ps, fd, pfd->events, events);
600
601 nxt_pollset_remove(engine, fd);
602 continue;
603 }
604
605 nxt_debug(ev->task, "pollset: fd:%d ev:%04uXi", fd, events);
606
607 if (nxt_slow_path(events & (POLLERR | POLLHUP | POLLNVAL)) != 0) {
598
599 nxt_pollset_remove(engine, fd);
600 continue;
601 }
602
603 nxt_debug(ev->task, "pollset: fd:%d ev:%04uXi", fd, events);
604
605 if (nxt_slow_path(events & (POLLERR | POLLHUP | POLLNVAL)) != 0) {
608 nxt_log(ev->task, NXT_LOG_CRIT,
609 "pollset_poll(%d) error fd:%d ev:%04Xd rev:%04uXi",
610 engine->u.pollset.ps, fd, pfd->events, events);
606 nxt_alert(ev->task,
607 "pollset_poll(%d) error fd:%d ev:%04Xd rev:%04uXi",
608 engine->u.pollset.ps, fd, pfd->events, events);
611
612 nxt_work_queue_add(&engine->fast_work_queue, ev->error_handler,
613 ev->task, ev, ev->data);
614 continue;
615 }
616
617 if (events & POLLIN) {
618 ev->read_ready = 1;

--- 29 unchanged lines hidden ---
609
610 nxt_work_queue_add(&engine->fast_work_queue, ev->error_handler,
611 ev->task, ev, ev->data);
612 continue;
613 }
614
615 if (events & POLLIN) {
616 ev->read_ready = 1;

--- 29 unchanged lines hidden ---