socket_poll_events : 'poll -> timeout:float -> void Update the read/write flags arrays that were created with [socket_poll_prepare]. **/
| 1222 | </doc> |
| 1223 | **/ |
| 1224 | void _hx_std_socket_poll_events( Dynamic pdata, double timeout ) |
| 1225 | { |
| 1226 | polldata *p = val_poll(pdata); |
| 1227 | |
| 1228 | #ifdef NEKO_WINDOWS |
| 1229 | memcpy(p->outr,p->fdr,FDSIZE(p->fdr->fd_count)); |
| 1230 | memcpy(p->outw,p->fdw,FDSIZE(p->fdw->fd_count)); |
| 1231 | |
| 1232 | struct timeval t; |
| 1233 | struct timeval *tt = init_timeval(timeout,&t); |
| 1234 | |
| 1235 | hx::EnterGCFreeZone(); |
| 1236 | if( select(0/* Ignored */, p->fdr->fd_count ? p->outr : 0, p->fdw->fd_count ?p->outw : 0,NULL,tt) == SOCKET_ERROR ) |
| 1237 | { |
| 1238 | hx::ExitGCFreeZone(); |
| 1239 | return; |
| 1240 | } |
| 1241 | hx::ExitGCFreeZone(); |
| 1242 | |
| 1243 | int k = 0; |
| 1244 | for(int i=0;i<p->fdr->fd_count;i++) |
| 1245 | if( FD_ISSET(p->fdr->fd_array[i],p->outr) ) |
| 1246 | p->ridx[k++] = i; |
| 1247 | p->ridx[k] = -1; |
| 1248 | |
| 1249 | k = 0; |
| 1250 | for(int i=0;i<p->fdw->fd_count;i++) |
| 1251 | if( FD_ISSET(p->fdw->fd_array[i],p->outw) ) |
| 1252 | p->widx[k++] = i; |
| 1253 | p->widx[k] = -1; |
| 1254 | |
| 1255 | #else |
| 1256 | |
| 1257 | int tot = p->rcount + p->wcount; |
| 1258 | hx::EnterGCFreeZone(); |
| 1259 | POSIX_LABEL(poll_events_again); |
| 1260 | if( poll(p->fds,tot,(int)(timeout * 1000)) < 0 ) |
| 1261 | { |
| 1262 | HANDLE_EINTR(poll_events_again); |
| 1263 | hx::ExitGCFreeZone(); |
| 1264 | return; |
| 1265 | } |
| 1266 | hx::ExitGCFreeZone(); |
| 1267 | |
| 1268 | int k = 0; |
| 1269 | int i = 0; |
| 1270 | for(i=0;i<p->rcount;i++) |
| 1271 | if( p->fds[i].revents & (POLLIN|POLLHUP) ) |
| 1272 | p->ridx[k++] = i; |
| 1273 | p->ridx[k] = -1; |
| 1274 | k = 0; |
| 1275 | for(;i<tot;i++) |
| 1276 | if( p->fds[i].revents & (POLLOUT|POLLHUP) ) |
| 1277 | p->widx[k++] = i - p->rcount; |
| 1278 | p->widx[k] = -1; |
| 1279 | #endif |
| 1280 | } |
| 1281 |
no test coverage detected