@@ -70,6 +70,9 @@ inline static int io_wait_loop_poll(io_wait_h* h, int t, int repeat)
70
70
{
71
71
int n, r;
72
72
int ret;
73
+ struct fd_map *e;
74
+ unsigned int curr_time;
75
+
73
76
again:
74
77
ret=n=poll (h->fd_array , h->fd_no , t*1000 );
75
78
if (n==-1 ){
@@ -79,9 +82,11 @@ inline static int io_wait_loop_poll(io_wait_h* h, int t, int repeat)
79
82
goto error;
80
83
}
81
84
}
82
- for (r=h->fd_no -1 ; (r>=0 ) && n; r--){
85
+
86
+ curr_time = get_ticks ();
87
+
88
+ for (r=h->fd_no -1 ; (r>=0 ) ; r--){
83
89
if (h->fd_array [r].revents & POLLOUT) {
84
- n--;
85
90
/* sanity checks */
86
91
if ((h->fd_array [r].fd >= h->max_fd_no )||
87
92
(h->fd_array [r].fd < 0 )){
@@ -93,7 +98,6 @@ inline static int io_wait_loop_poll(io_wait_h* h, int t, int repeat)
93
98
}
94
99
handle_io (get_fd_map (h, h->fd_array [r].fd ),r,IO_WATCH_WRITE);
95
100
} else if (h->fd_array [r].revents & (POLLIN|POLLERR|POLLHUP)){
96
- n--;
97
101
/* sanity checks */
98
102
if ((h->fd_array [r].fd >= h->max_fd_no )||
99
103
(h->fd_array [r].fd < 0 )){
@@ -104,8 +108,13 @@ inline static int io_wait_loop_poll(io_wait_h* h, int t, int repeat)
104
108
continue ;
105
109
}
106
110
107
- while ((handle_io (get_fd_map (h, h->fd_array [r].fd ), r,IO_WATCH_READ) > 0 )
111
+ while ((handle_io (get_fd_map (h, h->fd_array [r].fd ), r,
112
+ IO_WATCH_READ) > 0 )
108
113
&& repeat);
114
+ } else if ( (e=get_fd_map (h, h->fd_array [r].fd ))!=NULL &&
115
+ e->timeout !=0 && e->timeout <=curr_time ) {
116
+ e->timeout = 0 ;
117
+ handle_io ( e, r, IO_WATCH_TIMEOUT);
109
118
}
110
119
}
111
120
error:
@@ -122,6 +131,8 @@ inline static int io_wait_loop_select(io_wait_h* h, int t, int repeat)
122
131
int n, ret;
123
132
struct timeval timeout;
124
133
int r;
134
+ struct fd_map *e;
135
+ unsigned int curr_time;
125
136
126
137
again:
127
138
sel_set=h->master_set ;
@@ -134,12 +145,18 @@ inline static int io_wait_loop_select(io_wait_h* h, int t, int repeat)
134
145
n=0 ;
135
146
/* continue */
136
147
}
148
+
149
+ curr_time = get_ticks ();
150
+
137
151
/* use poll fd array */
138
- for (r=h->fd_no -1 ; (r>=0 ) && n ; r--){
152
+ for (r=h->fd_no -1 ; (r>=0 ) ; r--){
139
153
if (FD_ISSET (h->fd_array [r].fd , &sel_set)){
140
- while ((handle_io (get_fd_map (h, h->fd_array [r].fd ), r,IO_WATCH_READ)>0 )
141
- && repeat);
142
- n--;
154
+ while ( (handle_io ( get_fd_map (h, h->fd_array [r].fd ), r,
155
+ IO_WATCH_READ)>0 ) && repeat );
156
+ } else if ( (e=get_fd_map (h, h->fd_array [r].fd ))!=NULL &&
157
+ e->timeout !=0 && e->timeout <=curr_time ) {
158
+ e->timeout = 0 ;
159
+ handle_io ( e, r, IO_WATCH_TIMEOUT);
143
160
}
144
161
};
145
162
return ret;
@@ -155,6 +172,7 @@ inline static int io_wait_loop_epoll(io_wait_h* h, int t, int repeat)
155
172
struct fd_map *e;
156
173
struct epoll_event ep_event;
157
174
int fd;
175
+ unsigned int curr_time;
158
176
159
177
again:
160
178
ret=n=epoll_wait (h->epfd , h->ep_array , h->fd_no , t*1000 );
@@ -171,22 +189,29 @@ inline static int io_wait_loop_epoll(io_wait_h* h, int t, int repeat)
171
189
goto error;
172
190
}
173
191
}
192
+
193
+ curr_time = get_ticks ();
194
+
174
195
for (r=0 ; r<n; r++) {
175
196
#if 0
176
197
LM_NOTICE("[%s] triggering fd %d, events %d, flags %d\n",
177
198
h->name, ((struct fd_map*)h->ep_array[r].data.ptr)->fd,
178
- h->ep_array[r].events, ((struct fd_map*)h->ep_array[r].data.ptr)->flags);
199
+ h->ep_array[r].events,
200
+ ((struct fd_map*)h->ep_array[r].data.ptr)->flags);
179
201
#endif
180
202
/* do some sanity check over the triggered fd */
181
203
e = ((struct fd_map *)h->ep_array [r].data .ptr );
182
- if (e->type ==0 || e->fd <=0 || (e->flags &(IO_WATCH_READ|IO_WATCH_WRITE))==0 ) {
204
+ if (e->type ==0 || e->fd <=0 ||
205
+ (e->flags &(IO_WATCH_READ|IO_WATCH_WRITE))==0 ) {
183
206
fd = e - h->fd_hash ;
184
- LM_ERR (" [%s] unset/bogus map (idx=%d) triggered for %d by epoll "
185
- " (fd=%d,type=%d,flags=%x,data=%p) -> removing from epoll\n " , h->name ,
207
+ LM_ERR (" [%s] unset/bogus map (idx=%d) triggered for %d by "
208
+ " epoll (fd=%d,type=%d,flags=%x,data=%p) -> removing "
209
+ " from epoll\n " , h->name ,
186
210
fd, h->ep_array [r].events ,
187
211
e->fd , e->type , e->flags , e->data );
188
212
/* as the triggering fd has no corresponding in fd_map, better
189
- remove it from poll, to avoid un-managed reporting on this fd */
213
+ * remove it from poll, to avoid un-managed reporting
214
+ * on this fd */
190
215
if (epoll_ctl (h->epfd , EPOLL_CTL_DEL, fd, &ep_event)<0 ) {
191
216
LM_ERR (" failed to remove from epoll %s(%d)\n " ,
192
217
strerror (errno), errno);
@@ -249,7 +274,7 @@ inline static int io_wait_loop_epoll(io_wait_h* h, int t, int repeat)
249
274
}
250
275
}
251
276
/* now do the actual running of IO handlers */
252
- for (r=h->fd_no -1 ; (r>=0 ) && n ; r--) {
277
+ for (r=h->fd_no -1 ; (r>=0 ) ; r--) {
253
278
e = get_fd_map (h, h->fd_array [r].fd );
254
279
/* test the sanity of the fd_map */
255
280
if (e->flags & (IO_WATCH_PRV_TRIG_READ|IO_WATCH_PRV_TRIG_WRITE)) {
@@ -278,11 +303,12 @@ inline static int io_wait_loop_epoll(io_wait_h* h, int t, int repeat)
278
303
if ( e->flags & IO_WATCH_PRV_TRIG_READ ) {
279
304
e->flags &= ~IO_WATCH_PRV_TRIG_READ;
280
305
while ((handle_io ( e, r, IO_WATCH_READ)>0 ) && repeat);
281
- n--;
282
306
} else if ( e->flags & IO_WATCH_PRV_TRIG_WRITE ){
283
307
e->flags &= ~IO_WATCH_PRV_TRIG_WRITE;
284
308
handle_io ( e, r, IO_WATCH_WRITE);
285
- n--;
309
+ } else if ( e->timeout !=0 && e->timeout <=curr_time ) {
310
+ e->timeout = 0 ;
311
+ handle_io ( e, r, IO_WATCH_TIMEOUT);
286
312
}
287
313
}
288
314
@@ -299,6 +325,7 @@ inline static int io_wait_loop_kqueue(io_wait_h* h, int t, int repeat)
299
325
int ret, n, r;
300
326
struct timespec tspec;
301
327
struct fd_map *e;
328
+ unsigned int curr_time;
302
329
303
330
tspec.tv_sec =t;
304
331
tspec.tv_nsec =0 ;
@@ -308,15 +335,20 @@ inline static int io_wait_loop_kqueue(io_wait_h* h, int t, int repeat)
308
335
if (n==-1 ){
309
336
if (errno==EINTR) goto again; /* signal, ignore it */
310
337
else {
311
- LM_ERR (" [%s] kevent: %s [%d]\n " , h->name , strerror (errno), errno);
338
+ LM_ERR (" [%s] kevent: %s [%d]\n " , h->name ,
339
+ strerror (errno), errno);
312
340
goto error;
313
341
}
314
342
}
343
+
344
+ curr_time = get_ticks ();
345
+
315
346
h->kq_nchanges =0 ; /* reset changes array */
316
347
for (r=0 ; r<n; r++){
317
348
#ifdef EXTRA_DEBUG
318
349
LM_DBG (" [%s] event %d/%d: fd=%d, udata=%lx, flags=0x%x\n " ,
319
- h->name , r, n, h->kq_array [r].ident , (long )h->kq_array [r].udata ,
350
+ h->name , r, n, h->kq_array [r].ident ,
351
+ (long )h->kq_array [r].udata ,
320
352
h->kq_array [r].flags );
321
353
#endif
322
354
if (h->kq_array [r].flags & EV_ERROR){
@@ -339,6 +371,9 @@ inline static int io_wait_loop_kqueue(io_wait_h* h, int t, int repeat)
339
371
e->flags &= ~IO_WATCH_PRV_TRIG_READ;
340
372
while ((handle_io ( e, r, IO_WATCH_READ)>0 ) && repeat);
341
373
n--;
374
+ } else if ( e->timeout !=0 && e->timeout <=curr_time ) {
375
+ e->timeout = 0 ;
376
+ handle_io ( e, r, IO_WATCH_TIMEOUT);
342
377
}
343
378
}
344
379
@@ -361,7 +396,6 @@ inline static int io_wait_loop_sigio_rt(io_wait_h* h, int t)
361
396
int sigio_fd;
362
397
struct fd_map * fm;
363
398
364
-
365
399
ret=1 ; /* 1 event per call normally */
366
400
ts.tv_sec =t;
367
401
ts.tv_nsec =0 ;
@@ -469,6 +503,7 @@ inline static int io_wait_loop_devpoll(io_wait_h* h, int t, int repeat)
469
503
int ret;
470
504
struct dvpoll dpoll;
471
505
struct fd_map *e;
506
+ unsigned int curr_time;
472
507
473
508
dpoll.dp_timeout =t*1000 ;
474
509
dpoll.dp_nfds =h->fd_no ;
@@ -482,6 +517,9 @@ inline static int io_wait_loop_devpoll(io_wait_h* h, int t, int repeat)
482
517
goto error;
483
518
}
484
519
}
520
+
521
+ curr_time = get_ticks ();
522
+
485
523
for (r=0 ; r< n; r++){
486
524
if (h->dp_changes [r].revents & (POLLNVAL|POLLERR)){
487
525
LM_ERR (" [%s] pollinval returned for fd %d, revents=%x\n " ,
@@ -492,12 +530,14 @@ inline static int io_wait_loop_devpoll(io_wait_h* h, int t, int repeat)
492
530
IO_WATCH_PRV_TRIG_READ;
493
531
}
494
532
/* now do the actual running of IO handlers */
495
- for (r=h->fd_no -1 ; (r>=0 ) && n ; r--) {
533
+ for (r=h->fd_no -1 ; (r>=0 ) ; r--) {
496
534
e = get_fd_map (h, h->fd_array [r].fd );
497
535
if ( e->flags & IO_WATCH_PRV_TRIG_READ ) {
498
536
e->flags &= ~IO_WATCH_PRV_TRIG_READ;
499
537
while ((handle_io ( e, r, IO_WATCH_READ)>0 ) && repeat);
500
- n--;
538
+ } else if ( e->timeout !=0 && e->timeout <=curr_time ) {
539
+ e->timeout = 0 ;
540
+ handle_io ( e, r, IO_WATCH_TIMEOUT);
501
541
}
502
542
}
503
543
0 commit comments