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

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

541 continue;
542 }
543
544 fd = pfd->fd;
545
546 phe = nxt_poll_fd_hash_get(engine, fd);
547
548 if (nxt_slow_path(phe == NULL)) {
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

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

541 continue;
542 }
543
544 fd = pfd->fd;
545
546 phe = nxt_poll_fd_hash_get(engine, fd);
547
548 if (nxt_slow_path(phe == NULL)) {
549 nxt_log(&engine->task, NXT_LOG_CRIT,
550 "poll() returned invalid fd:%d ev:%04Xd rev:%04uXi",
551 fd, pfd->events, events);
549 nxt_alert(&engine->task,
550 "poll() returned invalid fd:%d ev:%04Xd rev:%04uXi",
551 fd, pfd->events, events);
552
553 /* Mark the poll entry to ignore it by the kernel. */
554 pfd->fd = -1;
555 goto next;
556 }
557
558 ev = phe->event;
559
560 nxt_debug(ev->task, "poll: fd:%d ev:%04uXi rd:%d wr:%d",
561 fd, events, ev->read, ev->write);
562
563 if (nxt_slow_path((events & POLLNVAL) != 0)) {
552
553 /* Mark the poll entry to ignore it by the kernel. */
554 pfd->fd = -1;
555 goto next;
556 }
557
558 ev = phe->event;
559
560 nxt_debug(ev->task, "poll: fd:%d ev:%04uXi rd:%d wr:%d",
561 fd, events, ev->read, ev->write);
562
563 if (nxt_slow_path((events & POLLNVAL) != 0)) {
564 nxt_log(ev->task, NXT_LOG_CRIT,
565 "poll() error fd:%d ev:%04Xd rev:%04uXi",
566 fd, pfd->events, events);
564 nxt_alert(ev->task, "poll() error fd:%d ev:%04Xd rev:%04uXi",
565 fd, pfd->events, events);
567
568 /* Mark the poll entry to ignore it by the kernel. */
569 pfd->fd = -1;
570
571 nxt_work_queue_add(&engine->fast_work_queue,
572 ev->error_handler, ev->task, ev, ev->data);
573 goto next;
574 }

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

644 lhq.proto = &nxt_poll_fd_hash_proto;
645 lhq.data = engine;
646
647 if (nxt_lvlhsh_find(&engine->u.poll.fd_hash, &lhq) == NXT_OK) {
648 phe = lhq.value;
649 return phe;
650 }
651
566
567 /* Mark the poll entry to ignore it by the kernel. */
568 pfd->fd = -1;
569
570 nxt_work_queue_add(&engine->fast_work_queue,
571 ev->error_handler, ev->task, ev, ev->data);
572 goto next;
573 }

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

643 lhq.proto = &nxt_poll_fd_hash_proto;
644 lhq.data = engine;
645
646 if (nxt_lvlhsh_find(&engine->u.poll.fd_hash, &lhq) == NXT_OK) {
647 phe = lhq.value;
648 return phe;
649 }
650
652 nxt_log(&engine->task, NXT_LOG_CRIT, "fd %d not found in hash", fd);
651 nxt_alert(&engine->task, "fd %d not found in hash", fd);
653
654 return NULL;
655}
656
657
658static nxt_int_t
659nxt_poll_fd_hash_test(nxt_lvlhsh_query_t *lhq, void *data)
660{

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

666 /* nxt_murmur_hash2() is unique for 4 bytes. */
667
668 engine = lhq->data;
669
670 if (nxt_fast_path(phe->fd == engine->u.poll.set[phe->index].fd)) {
671 return NXT_OK;
672 }
673
652
653 return NULL;
654}
655
656
657static nxt_int_t
658nxt_poll_fd_hash_test(nxt_lvlhsh_query_t *lhq, void *data)
659{

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

665 /* nxt_murmur_hash2() is unique for 4 bytes. */
666
667 engine = lhq->data;
668
669 if (nxt_fast_path(phe->fd == engine->u.poll.set[phe->index].fd)) {
670 return NXT_OK;
671 }
672
674 nxt_log(&engine->task, NXT_LOG_CRIT,
675 "fd %d in hash mismatches fd %d in poll set",
676 phe->fd, engine->u.poll.set[phe->index].fd);
673 nxt_alert(&engine->task, "fd %d in hash mismatches fd %d in poll set",
674 phe->fd, engine->u.poll.set[phe->index].fd);
677
678 return NXT_DECLINED;
679}
680
681
682static void
683nxt_poll_fd_hash_destroy(nxt_event_engine_t *engine, nxt_lvlhsh_t *lh)
684{

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

695
696 if (phe == NULL) {
697 return;
698 }
699
700 lhq.key_hash = nxt_murmur_hash2(&phe->fd, sizeof(nxt_fd_t));
701
702 if (nxt_lvlhsh_delete(lh, &lhq) != NXT_OK) {
675
676 return NXT_DECLINED;
677}
678
679
680static void
681nxt_poll_fd_hash_destroy(nxt_event_engine_t *engine, nxt_lvlhsh_t *lh)
682{

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

693
694 if (phe == NULL) {
695 return;
696 }
697
698 lhq.key_hash = nxt_murmur_hash2(&phe->fd, sizeof(nxt_fd_t));
699
700 if (nxt_lvlhsh_delete(lh, &lhq) != NXT_OK) {
703 nxt_log(&engine->task, NXT_LOG_CRIT,
704 "event fd %d not found in hash", phe->fd);
701 nxt_alert(&engine->task, "event fd %d not found in hash", phe->fd);
705 }
706
707 nxt_free(phe);
708 }
709}
702 }
703
704 nxt_free(phe);
705 }
706}