- if( !p_sys->b_kfir )
- {
- /* Find if some data is available. This won't work under Windows. */
- struct timeval timeout;
- fd_set fds;
-
- /* Initialize file descriptor set */
- FD_ZERO( &fds );
- FD_SET( p_sys->fd, &fds );
-
- /* We'll wait 0.5 second if nothing happens */
- timeout.tv_sec = 0;
- timeout.tv_usec = 500000;
-
- /* Find if some data is available */
- while( (i_ret = select( p_sys->fd + 1, &fds, NULL, NULL, &timeout )) == 0
- || (i_ret < 0 && errno == EINTR) )
- {
- FD_ZERO( &fds );
- FD_SET( p_sys->fd, &fds );
- timeout.tv_sec = 0;
- timeout.tv_usec = 500000;
-
- if( p_access->b_die )
- return 0;
- }
-
- if( i_ret < 0 )
- {
- msg_Err( p_access, "select error (%s)", strerror(errno) );
- return -1;
- }
-
- i_ret = read( p_sys->fd, p_buffer, i_len );
- }
- else
- {
- /* b_kfir ; work around a buggy poll() driver implementation */
- while ( (i_ret = read( p_sys->fd, p_buffer, i_len )) == 0 &&
- !p_access->b_die )
- {
- msleep( INPUT_ERROR_SLEEP );
- }
- }
+ /* Note that POSIX regular files (b_seekable) opened for read are
+ * guaranteed to always set POLLIN immediately, so we can spare
+ * poll()ing them. */
+ /* Wait until some data is available. Impossible on Windows. */
+ struct pollfd ufd[2] = {
+ { .fd = fd, .events = POLLIN, },
+ { .fd = vlc_object_waitpipe (p_access), .events = POLLIN, },
+ };
+
+ if (poll (ufd, 2, -1) < 0 || ufd[1].revents)
+ return -1;