45
45
#include "util/netevent.h"
46
46
#include "util/fptr_wlist.h"
47
47
#include "util/ub_event.h"
48
+ #ifdef HAVE_POLL_H
49
+ #include <poll.h>
50
+ #endif
48
51
49
52
#ifndef USE_WINSOCK
50
53
/* on unix */
@@ -396,20 +399,28 @@ int tube_read_msg(struct tube* tube, uint8_t** buf, uint32_t* len,
396
399
return 1 ;
397
400
}
398
401
399
- /** perform a select () on the fd */
402
+ /** perform poll () on the fd */
400
403
static int
401
404
pollit (int fd , struct timeval * t )
402
405
{
403
- fd_set r ;
406
+ struct pollfd fds ;
407
+ int pret ;
408
+ int msec = -1 ;
409
+ memset (& fds , 0 , sizeof (fds ));
410
+ fds .fd = fd ;
411
+ fds .events = POLLIN | POLLERR | POLLHUP ;
404
412
#ifndef S_SPLINT_S
405
- FD_ZERO ( & r );
406
- FD_SET ( FD_SET_T fd , & r ) ;
413
+ if ( t )
414
+ msec = t -> tv_sec * 1000 + t -> tv_usec / 1000 ;
407
415
#endif
408
- if (select (fd + 1 , & r , NULL , NULL , t ) == -1 ) {
416
+
417
+ pret = poll (& fds , 1 , msec );
418
+
419
+ if (pret == -1 )
409
420
return 0 ;
410
- }
411
- errno = 0 ;
412
- return ( int )( FD_ISSET ( fd , & r )) ;
421
+ if ( pret != 0 )
422
+ return 1 ;
423
+ return 0 ;
413
424
}
414
425
415
426
int tube_poll (struct tube * tube )
@@ -426,24 +437,27 @@ int tube_wait(struct tube* tube)
426
437
427
438
int tube_wait_timeout (struct tube * tube , int msec )
428
439
{
429
- struct timeval t ;
430
- int fd = tube -> sr ;
431
- fd_set r ;
432
- t .tv_sec = msec /1000 ;
433
- t .tv_usec = (msec %1000 )* 1000 ;
434
- #ifndef S_SPLINT_S
435
- FD_ZERO (& r );
436
- FD_SET (FD_SET_T fd , & r );
437
- #endif
440
+ int ret = 0 ;
441
+
438
442
while (1 ) {
439
- if (select (fd + 1 , & r , NULL , NULL , & t ) == -1 ) {
443
+ struct pollfd fds ;
444
+ memset (& fds , 0 , sizeof (fds ));
445
+
446
+ fds .fd = tube -> sr ;
447
+ fds .events = POLLIN | POLLERR | POLLHUP ;
448
+ ret = poll (& fds , 1 , msec );
449
+
450
+ if (ret == -1 ) {
440
451
if (errno == EAGAIN || errno == EINTR )
441
452
continue ;
442
453
return -1 ;
443
454
}
444
455
break ;
445
456
}
446
- return (int )(FD_ISSET (fd , & r ));
457
+
458
+ if (ret != 0 )
459
+ return 1 ;
460
+ return 0 ;
447
461
}
448
462
449
463
int tube_read_fd (struct tube * tube )
0 commit comments