Commit e8f36f6e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

net_Recv(): improve error handling (fixes #9081)

parent a4e524f1
...@@ -61,6 +61,10 @@ ...@@ -61,6 +61,10 @@
#if defined(_WIN32) #if defined(_WIN32)
# undef EAFNOSUPPORT # undef EAFNOSUPPORT
# define EAFNOSUPPORT WSAEAFNOSUPPORT # define EAFNOSUPPORT WSAEAFNOSUPPORT
# undef EWOULDBLOCK
# define EWOULDBLOCK WSAEWOULDBLOCK
# undef EAGAIN
# define EAGAIN WSAEWOULDBLOCK
#endif #endif
#ifdef HAVE_LINUX_DCCP_H #ifdef HAVE_LINUX_DCCP_H
...@@ -286,13 +290,15 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs, ...@@ -286,13 +290,15 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
{ {
switch (net_errno) switch (net_errno)
{ {
case EAGAIN: /* spurious wakeup or no TLS data */ case EAGAIN: /* no data */
#if (EAGAIN != EWOULDBLOCK) #if (EAGAIN != EWOULDBLOCK)
case EWOULDBLOCK: case EWOULDBLOCK:
#endif #endif
case EINTR: /* asynchronous signal */
break; break;
#ifdef _WIN32 #ifndef _WIN32
case EINTR: /* asynchronous signal */
continue;
#else
case WSAEMSGSIZE: /* datagram too big */ case WSAEMSGSIZE: /* datagram too big */
n = i_buflen; n = i_buflen;
break; break;
...@@ -311,25 +317,26 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs, ...@@ -311,25 +317,26 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
if (!waitall) if (!waitall)
break; break;
} }
else else /* n == 0 */
break;/* end of stream or empty packet */ break;/* end of stream or empty packet */
/* Wait for more data */
if (ufd[1].fd == -1) if (ufd[1].fd == -1)
{ {
errno = EINTR; errno = EINTR;
return -1; return -1;
} }
while (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) < 0)
if (errno != EINTR) /* Wait for more data */
goto error; if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) < 0)
{
if (errno == EINTR)
continue;
goto error;
}
if (ufd[1].revents) if (ufd[1].revents)
{ {
msg_Dbg (p_this, "socket %d polling interrupted", fd); msg_Dbg (p_this, "socket %d polling interrupted", fd);
#if defined(_WIN32)
WSASetLastError (WSAEINTR);
#endif
errno = EINTR; errno = EINTR;
return -1; 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