[vlc-commits] win32: fix gnutls access

Rafaël Carré git at videolan.org
Wed Nov 23 19:47:34 CET 2011


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Fri Nov 18 20:57:44 2011 -0500| [1305c3e1bffb93e63a417c8b1dc691b78458cd42] | committer: Rafaël Carré

win32: fix gnutls access

reading failed with EAGAIN but this error was not catched properly

Signed-off-by: Rafaël Carré <funman at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1305c3e1bffb93e63a417c8b1dc691b78458cd42
---

 src/network/io.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/src/network/io.c b/src/network/io.c
index 8f92852..6011cec 100644
--- a/src/network/io.c
+++ b/src/network/io.c
@@ -310,16 +310,29 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
         assert (ufd[0].revents);
 
         ssize_t n;
+#if defined(WIN32) || defined(UNDER_CE)
+        int error;
+#endif
         if (vs != NULL)
         {
             int canc = vlc_savecancel ();
             n = vs->pf_recv (vs->p_sys, p_buf, i_buflen);
+#if defined(WIN32) || defined(UNDER_CE)
+            /* We must read last error immediately, because vlc_restorecancel()
+             * access thread local storage, and TlsGetValue() will call
+             * SetLastError() to indicate that the function succeeded, thus
+             * overwriting the error code coming from pf_recv().
+             * WSAGetLastError is just an alias for GetLastError these days.
+             */
+            error = WSAGetLastError();
+#endif
             vlc_restorecancel (canc);
         }
         else
         {
 #ifdef WIN32
             n = recv (fd, p_buf, i_buflen, 0);
+            error = WSAGetLastError();
 #else
             n = read (fd, p_buf, i_buflen);
 #endif
@@ -328,7 +341,7 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
         if (n == -1)
         {
 #if defined(WIN32) || defined(UNDER_CE)
-            switch (WSAGetLastError ())
+            switch (error)
             {
                 case WSAEWOULDBLOCK:
                 case WSAEINTR:



More information about the vlc-commits mailing list