! \brief wait for io using select */
| 126 | #ifdef HAVE_SELECT |
| 127 | /*! \brief wait for io using select */ |
| 128 | inline static int io_wait_loop_select(io_wait_h* h, int t, int repeat) |
| 129 | { |
| 130 | fd_set sel_set; |
| 131 | int n, ret; |
| 132 | struct timeval timeout; |
| 133 | int r; |
| 134 | struct fd_map *e; |
| 135 | unsigned int curr_time; |
| 136 | |
| 137 | again: |
| 138 | sel_set=h->master_set; |
| 139 | timeout.tv_sec=t; |
| 140 | timeout.tv_usec=0; |
| 141 | ret=n=select(h->max_fd_select+1, &sel_set, 0, 0, &timeout); |
| 142 | if (n<0){ |
| 143 | if (errno==EINTR) goto again; /* just a signal */ |
| 144 | LM_ERR("[%s] select: %s [%d]\n",h->name, strerror(errno), errno); |
| 145 | n=0; |
| 146 | /* continue */ |
| 147 | } |
| 148 | |
| 149 | curr_time = get_ticks(); |
| 150 | |
| 151 | /* use poll fd array */ |
| 152 | for(r=h->fd_no-1; (r>=0) ; r--){ |
| 153 | if (FD_ISSET(h->fd_array[r].fd, &sel_set)){ |
| 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); |
| 160 | } |
| 161 | }; |
| 162 | return ret; |
| 163 | } |
| 164 | #endif |
| 165 | |
| 166 |