]> git.sesse.net Git - vlc/blobdiff - src/network/tcp.c
httpd: use c99 for
[vlc] / src / network / tcp.c
index 61159e0fd267e5c252777d346a93bc21bb4c34d5..083861d8ede48166ea62a6da138d2f78cd1ad34f 100644 (file)
 
 #include <errno.h>
 #include <assert.h>
-
-#ifdef HAVE_UNISTD_H
-#   include <unistd.h>
-#endif
+#include <unistd.h>
 #ifdef HAVE_POLL
 # include <poll.h>
 #endif
 #   define EINPROGRESS WSAEWOULDBLOCK
 #   undef EWOULDBLOCK
 #   define EWOULDBLOCK WSAEWOULDBLOCK
+#   undef EAGAIN
+#   define EAGAIN WSAEWOULDBLOCK
 #   undef EINTR
 #   define EINTR WSAEINTR
-#   undef ETIMEDOUT
-#   define ETIMEDOUT WSAETIMEDOUT
 #endif
 
 #include "libvlc.h" /* vlc_object_waitpipe */
@@ -138,14 +135,15 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
     }, *res;
 
     int val = vlc_getaddrinfo (psz_realhost, i_realport, &hints, &res);
-    free( psz_socks );
 
     if (val)
     {
         msg_Err (p_this, "cannot resolve %s port %d : %s", psz_realhost,
                  i_realport, gai_strerror (val));
+        free( psz_socks );
         return -1;
     }
+    free( psz_socks );
 
     int timeout = var_InheritInteger (p_this, "ipv4-timeout");
     if (timeout < 0)
@@ -157,7 +155,7 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
                              ptr->ai_socktype, ptr->ai_protocol );
         if( fd == -1 )
         {
-            msg_Dbg( p_this, "socket error: %m" );
+            msg_Dbg( p_this, "socket error: %s", vlc_strerror_c(net_errno) );
             continue;
         }
 
@@ -167,7 +165,8 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
 
             if( net_errno != EINPROGRESS && net_errno != EINTR )
             {
-                msg_Err( p_this, "connection failed: %m" );
+                msg_Err( p_this, "connection failed: %s",
+                         vlc_strerror_c(net_errno) );
                 goto next_ai;
             }
 
@@ -184,7 +183,8 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
             switch (val)
             {
                  case -1: /* error */
-                     msg_Err (p_this, "connection polling error: %m");
+                     msg_Err (p_this, "polling error: %s",
+                              vlc_strerror_c(net_errno));
                      goto next_ai;
 
                  case 0: /* timeout */
@@ -201,8 +201,8 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
             if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &val,
                             &(socklen_t){ sizeof (val) }) || val)
             {
-                errno = val;
-                msg_Err (p_this, "connection failed: %m");
+                msg_Err (p_this, "connection failed: %s",
+                         vlc_strerror_c(val));
                 goto next_ai;
             }
         }
@@ -249,7 +249,8 @@ int net_AcceptSingle (vlc_object_t *obj, int lfd)
     if (fd == -1)
     {
         if (net_errno != EAGAIN && net_errno != EWOULDBLOCK)
-            msg_Err (obj, "accept failed (from socket %d): %m", lfd);
+            msg_Err (obj, "accept failed (from socket %d): %s", lfd,
+                     vlc_strerror_c(net_errno));
         return -1;
     }
 
@@ -296,7 +297,7 @@ int net_Accept (vlc_object_t *p_this, int *pi_fd)
         {
             if (net_errno != EINTR)
             {
-                msg_Err (p_this, "poll error: %m");
+                msg_Err (p_this, "poll error: %s", vlc_strerror_c(net_errno));
                 return -1;
             }
         }
@@ -348,17 +349,14 @@ static int SocksNegotiate( vlc_object_t *p_obj,
         return VLC_SUCCESS;
 
     /* We negotiate authentication */
-
-    if( ( psz_socks_user == NULL ) && ( psz_socks_passwd == NULL ) )
-        b_auth = true;
-
     buffer[0] = i_socks_version;    /* SOCKS version */
-    if( b_auth )
+    if( psz_socks_user != NULL && psz_socks_passwd != NULL )
     {
         buffer[1] = 2;                  /* Number of methods */
         buffer[2] = 0x00;               /* - No auth required */
         buffer[3] = 0x02;               /* - USer/Password */
         i_len = 4;
+        b_auth = true;
     }
     else
     {