comparison src/event/modules/ngx_sigio_module.c @ 60:50186b49f2ad

nginx-0.0.1-2003-02-11-10:14:40 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 11 Feb 2003 07:14:40 +0000
parents
children 6753e8cdaa2c
comparison
equal deleted inserted replaced
59:e8cdc2989cee 60:50186b49f2ad
1
2
3 int ngx_sigio_add_event(ngx_event_t *ev, int signal)
4 {
5 ngx_connection_t *c;
6
7 c = (ngx_connection_t *) ev->data;
8
9 if (fcntl(c->fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC) == -1) {
10 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
11 "fcntl(O_RDWR|O_NONBLOCK|O_ASYNC) failed");
12 return NGX_ERROR;
13 }
14
15 if (fcntl(c->fd, F_SETSIG, signal) == -1) {
16 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
17 "fcntl(F_SETSIG) failed");
18 return NGX_ERROR;
19 }
20
21 if (fcntl(c->fd, F_SETOWN, pid) == -1) {
22 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
23 "fcntl(F_SETOWN) failed");
24 return NGX_ERROR;
25 }
26
27 #if (HAVE_ONESIGFD)
28 if (fcntl(c->fd, F_SETAUXFL, O_ONESIGFD) == -1) {
29 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
30 "fcntl(F_SETAUXFL) failed");
31 return NGX_ERROR;
32 }
33 #endif
34
35 return NGX_OK;
36 }
37
38 int ngx_sigio_process_events(ngx_log_t *log)
39 {
40 struct siginfo si;
41
42 for ( ;; ) {
43 if (timer) {
44 sig = sigtimedwait(&sigio_set, &si, &ts);
45
46 if (sig == -1) {
47 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
48 "sigtimedwait() failed");
49 continue;
50 }
51 }
52
53 } else {
54 sig = sigwaitinfo(&set, &si);
55
56 if (sig == -1) {
57 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
58 "sigwaitinfo() failed");
59 }
60 }
61
62 if (sig == rtsig) {
63 c = &ngx_connections[si.si_fd];
64
65 if (si.si_band & (POLLERR|POLLHUP|POLLNVAL)) {
66 ev = ???;
67
68 if (ev->active) {
69 ev->ready = 1;
70 if (ev->event_handler(ev) == NGX_ERROR) {
71 ev->close_handler(ev);
72 }
73 }
74 }
75
76 if (si.si_band & (POLLIN)) {
77 ev = c->read;
78
79 if (ev->active) {
80 ev->ready = 1;
81 if (ev->event_handler(ev) == NGX_ERROR) {
82 ev->close_handler(ev);
83 }
84 }
85 }
86
87 if (si.si_band & (POLLOUT)) {
88 ev = c->write;
89
90 if (ev->active) {
91 ev->ready = 1;
92 if (ev->event_handler(ev) == NGX_ERROR) {
93 ev->close_handler(ev);
94 }
95 }
96 }
97
98 } else if (sig == SIGIO) {
99 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
100 "Signal queue overflowed: "
101 "SIGIO, fd:%d, band:%d", si.si_fd, si.si_band);
102
103 /* flush queue: method #1 (dphttpd) */
104 ts.tv_sec = 0;
105 ts.tv_nsec = 0;
106 while (sigtimedwait(&sigio_set, &si, &ts) > 0);
107
108 /* flush queue: method #2 (dkftpbench) */
109 signal(m_signum, SIG_IGN);
110 signal(m_signum, SIG_DFL);
111
112 /* do poll */
113
114 } else {
115 }
116 }
117 }