@@ -301,3 +301,57 @@ int p_munmap(git_map *map)
301301}
302302
303303#endif
304+
305+ #if defined(GIT_IO_POLL ) || defined(GIT_IO_WSAPOLL )
306+
307+ /* Handled by posix.h; this test simplifies the final else */
308+
309+ #elif defined(GIT_IO_SELECT )
310+
311+ int p_poll (struct pollfd * fds , unsigned int nfds , int timeout_ms )
312+ {
313+ fd_set read_fds , write_fds , except_fds ;
314+ struct timeval timeout = { 0 , 0 };
315+ unsigned int i ;
316+ int max_fd = -1 , ret ;
317+
318+ FD_ZERO (& read_fds );
319+ FD_ZERO (& write_fds );
320+ FD_ZERO (& except_fds );
321+
322+ for (i = 0 ; i < nfds ; i ++ ) {
323+ if ((fds [i ].events & POLLIN ))
324+ FD_SET (fds [i ].fd , & read_fds );
325+
326+ if ((fds [i ].events & POLLOUT ))
327+ FD_SET (fds [i ].fd , & write_fds );
328+
329+ if ((fds [i ].events & POLLPRI ))
330+ FD_SET (fds [i ].fd , & except_fds );
331+
332+ max_fd = MAX (max_fd , fds [i ].fd );
333+ }
334+
335+ if (timeout_ms > 0 ) {
336+ timeout .tv_sec = timeout_ms / 1000 ;
337+ timeout .tv_usec = (timeout_ms % 1000 ) * 1000 ;
338+ }
339+
340+ if ((ret = select (max_fd + 1 , & read_fds , & write_fds , & except_fds ,
341+ timeout_ms < 0 ? NULL : & timeout )) < 0 )
342+ goto done ;
343+
344+ for (i = 0 ; i < nfds ; i ++ ) {
345+ fds [i ].revents = 0 |
346+ FD_ISSET (fds [i ].fd , & read_fds ) ? POLLIN : 0 |
347+ FD_ISSET (fds [i ].fd , & write_fds ) ? POLLOUT : 0 |
348+ FD_ISSET (fds [i ].fd , & except_fds ) ? POLLPRI : 0 ;
349+ }
350+
351+ done :
352+ return ret ;
353+ }
354+
355+ #else
356+ # error no poll compatible implementation
357+ #endif
0 commit comments