net_Close (fd);
#if !defined(WIN32) && !defined(UNDER_CE)
fd = rootwrap_bind (ptr->ai_family, socktype,
- protocol ?: ptr->ai_protocol, ptr->ai_addr,
- ptr->ai_addrlen);
+ protocol ? protocol : ptr->ai_protocol,
+ ptr->ai_addr, ptr->ai_addrlen);
if (fd != -1)
{
msg_Dbg (p_this, "got socket %d from rootwrap", fd);
/*****************************************************************************
* __net_Read:
*****************************************************************************
- * Reads from a network socket.
+ * Reads from a network socket. Cancellation point.
* 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 or the VLC
* object has been signaled.
*****************************************************************************/
ssize_t
__net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
- uint8_t *restrict p_buf, size_t i_buflen, bool waitall)
+ void *restrict p_buf, size_t i_buflen, bool waitall)
{
size_t i_total = 0;
struct pollfd ufd[2] = {
ssize_t n;
if (vs != NULL)
{
+ int canc = vlc_savecancel ();
n = vs->pf_recv (vs->p_sys, p_buf, i_buflen);
+ vlc_restorecancel (canc);
}
else
{
switch (errno)
{
case EAGAIN: /* spurious wakeup or no TLS data */
+#if (EAGAIN != EWOULDBLOCK)
+ case EWOULDBLOCK:
+#endif
case EINTR: /* asynchronous signal */
continue;
}
break; // EOF
i_total += n;
- p_buf += n;
+ p_buf = (char *)p_buf + n;
i_buflen -= n;
if (!waitall)
/* Write exact amount requested */
ssize_t __net_Write( vlc_object_t *p_this, int fd, const v_socket_t *p_vs,
- const uint8_t *p_data, size_t i_data )
+ const void *restrict p_data, size_t i_data )
{
size_t i_total = 0;
struct pollfd ufd[2] = {
ufd[0].revents = ufd[1].revents = 0;
- if (poll (ufd, 1, -1) == -1)
+ if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) == -1)
{
if (errno == EINTR)
continue;
break;
}
- p_data += val;
+ p_data = (const char *)p_data + val;
i_data -= val;
i_total += val;
}
return -1;
}
+/**
+ * Reads a line from a file descriptor.
+ * This function is not thread-safe; the same file descriptor cI/O annot be read
+ * by another thread at the same time (although it can be written to).
+ *
+ * @return nul-terminated heap-allocated string, or NULL on I/O error.
+ */
char *__net_Gets( vlc_object_t *p_this, int fd, const v_socket_t *p_vs )
{
char *psz_line = NULL, *ptr = NULL;
ptr = psz_line + i_line;
}
- if( net_Read( p_this, fd, p_vs, (uint8_t *)ptr, 1, true ) != 1 )
+ if( net_Read( p_this, fd, p_vs, ptr, 1, true ) != 1 )
{
if( i_line == 0 )
{
int i_size = vasprintf( &psz, psz_fmt, args );
if( i_size == -1 )
return -1;
- i_ret = __net_Write( p_this, fd, p_vs, (uint8_t *)psz, i_size ) < i_size
+ i_ret = __net_Write( p_this, fd, p_vs, psz, i_size ) < i_size
? -1 : i_size;
free( psz );
return i_ret;
}
-
-#ifdef WIN32
- /* vlc_sendmsg, vlc_recvmsg Defined in winsock.c */
-#else /* !WIN32 */
-ssize_t vlc_sendmsg (int s, struct msghdr *hdr, int flags)
-{
- return sendmsg (s, hdr, flags);
-}
-
-ssize_t vlc_recvmsg (int s, struct msghdr *hdr, int flags)
-{
- return recvmsg (s, hdr, flags);
-}
-#endif /* WIN32 */
-