Commit ecbbbc15 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Use the event pipe in net_Read instead of an arbitrary timer

parent 318d3056
...@@ -256,7 +256,7 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host, ...@@ -256,7 +256,7 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
/***************************************************************************** /*****************************************************************************
* __net_Read: * __net_Read:
***************************************************************************** *****************************************************************************
* Read from a network socket * Reads from a network socket.
* If waitall is true, then we repeat until we have read the right amount of * If waitall is true, then we repeat until we have read the right amount of
* data; in that case, a short count means EOF has been reached. * data; in that case, a short count means EOF has been reached.
*****************************************************************************/ *****************************************************************************/
...@@ -265,14 +265,20 @@ __net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs, ...@@ -265,14 +265,20 @@ __net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
uint8_t *restrict p_buf, size_t i_buflen, vlc_bool_t waitall) uint8_t *restrict p_buf, size_t i_buflen, vlc_bool_t waitall)
{ {
size_t i_total = 0; size_t i_total = 0;
struct pollfd ufd[1]; struct pollfd ufd[2] = {
ufd[0].fd = fd; { .fd = fd, .events = POLLIN },
ufd[0].events = POLLIN; { .fd = -1, .events = POLLIN },
};
msg_Dbg (p_this, "reading socket %d", fd);
vlc_object_lock (p_this);
ufd[1].fd = vlc_object_waitpipe (p_this);
while (i_buflen > 0) while (i_buflen > 0)
{ {
if( ( p_this->b_die ) || ( p_this->p_libvlc->b_die ) ) int val;
if (!vlc_object_alive (p_this))
{ {
#if defined(WIN32) || defined(UNDER_CE) #if defined(WIN32) || defined(UNDER_CE)
WSASetLastError (WSAEINTR); WSASetLastError (WSAEINTR);
...@@ -281,15 +287,20 @@ __net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs, ...@@ -281,15 +287,20 @@ __net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
#endif #endif
goto error; goto error;
} }
ufd[0].revents = ufd[1].revents = 0;
ufd[0].revents = 0; vlc_object_unlock (p_this);
/* TODO: don't use arbitrary timer just for b_die */ val = poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1);
switch (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), 500)) vlc_object_lock (p_this);
{
case -1: if (val < 0)
goto error; goto error;
case 0: // timeout if (ufd[1].revents)
{
msg_Dbg (p_this, "socket %d polling interrupted", fd);
vlc_object_wait (p_this);
msg_Dbg (p_this, "socket %d polling restarting", fd);
continue; continue;
} }
...@@ -304,7 +315,7 @@ __net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs, ...@@ -304,7 +315,7 @@ __net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
* otherwise we'd "hide" the error from the caller, which is a * otherwise we'd "hide" the error from the caller, which is a
* bad idea™. */ * bad idea™. */
if (ufd[0].revents & (POLLERR|POLLNVAL|POLLRDHUP)) if (ufd[0].revents & (POLLERR|POLLNVAL|POLLRDHUP))
return i_total; break;
} }
ssize_t n; ssize_t n;
...@@ -367,11 +378,16 @@ __net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs, ...@@ -367,11 +378,16 @@ __net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
if (!waitall) if (!waitall)
break; break;
} }
vlc_object_unlock (p_this);
msg_Dbg (p_this, "read %u bytes from socket %d", (unsigned)i_total, fd);
return i_total; return i_total;
error: error:
msg_Err (p_this, "Read error: %m"); msg_Err (p_this, "Read error: %m");
return i_total ? (ssize_t)i_total : -1;
vlc_object_unlock (p_this);
return -1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment