# include "config.h"
#endif
-#include <vlc/vlc.h>
+#include <vlc_common.h>
#include <errno.h>
#include <assert.h>
#if defined (WIN32) || defined (UNDER_CE)
# undef EINPROGRESS
# define EINPROGRESS WSAEWOULDBLOCK
+# undef EWOULDBLOCK
+# define EWOULDBLOCK WSAEWOULDBLOCK
# undef EINTR
# define EINTR WSAEINTR
# undef ETIMEDOUT
# define ETIMEDOUT WSAETIMEDOUT
#endif
-static int SocksNegociate( vlc_object_t *, int fd, int i_socks_version,
+#include "libvlc.h" /* vlc_object_waitpipe */
+
+static int SocksNegotiate( vlc_object_t *, int fd, int i_socks_version,
const char *psz_user, const char *psz_passwd );
static int SocksHandshakeTCP( vlc_object_t *,
int fd, int i_socks_version,
{
int timeout, val;
- if( net_errno != EINPROGRESS )
+ if( net_errno != EINPROGRESS && net_errno != EINTR )
{
msg_Err( p_this, "connection failed: %m" );
goto next_ai;
int net_AcceptSingle (vlc_object_t *obj, int lfd)
{
- int fd = accept (lfd, NULL, NULL);
+ int fd;
+ do
+ fd = accept (lfd, NULL, NULL);
+ while (fd == -1 && errno == EINTR);
+
if (fd == -1)
{
- if (net_errno != EAGAIN)
+ if (net_errno != EAGAIN && net_errno != EWOULDBLOCK)
msg_Err (obj, "accept failed (from socket %d): %m", lfd);
return -1;
}
int timeout = (i_wait < 0) ? -1 : i_wait / 1000;
int evfd = vlc_object_waitpipe (p_this);
- if (evfd == -1)
- return -1;
-
assert( pi_fd != NULL );
for (;;)
ufd[i].events = POLLIN;
ufd[i].revents = 0;
}
- if (evfd == -1)
- n--; /* avoid EBADF */
- switch (poll (ufd, n, timeout))
+ switch (poll (ufd, n + (evfd != -1), timeout))
{
case -1:
- if (net_errno != EINTR)
- msg_Err (p_this, "poll error: %m");
+ if (net_errno == EINTR)
+ continue;
+ msg_Err (p_this, "poll error: %m");
+ return -1;
case 0:
- return -1; /* NOTE: p_this already unlocked */
+ errno = ETIMEDOUT;
+ return -1;
}
if (ufd[n].revents)
/*****************************************************************************
- * SocksNegociate:
+ * SocksNegotiate:
*****************************************************************************
- * Negociate authentication with a SOCKS server.
+ * Negotiate authentication with a SOCKS server.
*****************************************************************************/
-static int SocksNegociate( vlc_object_t *p_obj,
+static int SocksNegotiate( vlc_object_t *p_obj,
int fd, int i_socks_version,
const char *psz_socks_user,
const char *psz_socks_passwd )
{
uint8_t buffer[128+2*256];
int i_len;
- vlc_bool_t b_auth = VLC_FALSE;
+ bool b_auth = false;
if( i_socks_version != 5 )
return VLC_SUCCESS;
- /* We negociate authentication */
+ /* We negotiate authentication */
if( ( psz_socks_user == NULL ) && ( psz_socks_passwd == NULL ) )
- b_auth = VLC_TRUE;
+ b_auth = true;
buffer[0] = i_socks_version; /* SOCKS version */
if( b_auth )
if( net_Write( p_obj, fd, NULL, buffer, i_len ) != i_len )
return VLC_EGENERIC;
- if( net_Read( p_obj, fd, NULL, buffer, 2, VLC_TRUE ) != 2 )
+ if( net_Read( p_obj, fd, NULL, buffer, 2, true ) != 2 )
return VLC_EGENERIC;
msg_Dbg( p_obj, "socks: v=%d method=%x", buffer[0], buffer[1] );
if( net_Write( p_obj, fd, NULL, buffer, i_len ) != i_len )
return VLC_EGENERIC;
- if( net_Read( p_obj, fd, NULL, buffer, 2, VLC_TRUE ) != 2 )
+ if( net_Read( p_obj, fd, NULL, buffer, 2, true ) != 2 )
return VLC_EGENERIC;
msg_Dbg( p_obj, "socks: v=%d status=%x", buffer[0], buffer[1] );
}
if( i_socks_version == 5 &&
- SocksNegociate( p_obj, fd, i_socks_version,
+ SocksNegotiate( p_obj, fd, i_socks_version,
psz_user, psz_passwd ) )
return VLC_EGENERIC;
if( net_Write( p_obj, fd, NULL, buffer, 9 ) != 9 )
return VLC_EGENERIC;
- if( net_Read( p_obj, fd, NULL, buffer, 8, VLC_TRUE ) != 8 )
+ if( net_Read( p_obj, fd, NULL, buffer, 8, true ) != 8 )
return VLC_EGENERIC;
msg_Dbg( p_obj, "socks: v=%d cd=%d",
return VLC_EGENERIC;
/* Read the header */
- if( net_Read( p_obj, fd, NULL, buffer, 5, VLC_TRUE ) != 5 )
+ if( net_Read( p_obj, fd, NULL, buffer, 5, true ) != 5 )
return VLC_EGENERIC;
msg_Dbg( p_obj, "socks: v=%d rep=%d atyp=%d",
if( buffer[1] != 0x00 )
{
- msg_Err( p_obj, "socks: CONNECT request failed\n" );
+ msg_Err( p_obj, "socks: CONNECT request failed" );
return VLC_EGENERIC;
}
else
return VLC_EGENERIC;
- if( net_Read( p_obj, fd, NULL, buffer, i_len, VLC_TRUE ) != i_len )
+ if( net_Read( p_obj, fd, NULL, buffer, i_len, true ) != i_len )
return VLC_EGENERIC;
}