+/*****************************************************************************
+ * Read: Read up to i_len bytes from the http connection and place in
+ * p_buffer. Return the actual number of bytes read
+ *****************************************************************************/
+static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
+{
+ input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
+ struct timeval timeout;
+ fd_set fds;
+ ssize_t i_recv;
+ int i_ret;
+
+ /* Initialize file descriptor set */
+ FD_ZERO( &fds );
+ FD_SET( p_access_data->i_handle, &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_access_data->i_handle + 1, &fds,
+ NULL, NULL, &timeout )) == 0
+#ifdef HAVE_ERRNO_H
+ || (i_ret < 0 && errno == EINTR)
+#endif
+ )
+ {
+ FD_ZERO( &fds );
+ FD_SET( p_access_data->i_handle, &fds );
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 500000;
+
+ if( p_input->b_die || p_input->b_error )
+ {
+ return 0;
+ }
+ }
+
+ if( i_ret < 0 )
+ {
+ msg_Err( p_input, "network select error" );
+ return -1;
+ }
+
+ i_recv = recv( p_access_data->i_handle, p_buffer, i_len, 0 );
+
+ if( i_recv < 0 )
+ {
+#ifdef HAVE_ERRNO_H
+ msg_Err( p_input, "recv failed (%s)", strerror(errno) );
+#else
+ msg_Err( p_input, "recv failed" );
+#endif
+ }
+
+ return i_recv;
+}