[vlc-devel] [PATCH] network: io: check virtual sockets own buffers (fix #8972)

Francois Cartegnie fcvlcdev at free.fr
Mon Jul 15 18:14:22 CEST 2013


---
 include/vlc_network.h |  1 +
 modules/misc/gnutls.c |  9 +++++++++
 src/network/io.c      | 10 ++++++++++
 3 files changed, 20 insertions(+)

diff --git a/include/vlc_network.h b/include/vlc_network.h
index 699e8af..cf16e7d 100644
--- a/include/vlc_network.h
+++ b/include/vlc_network.h
@@ -140,6 +140,7 @@ VLC_API int net_SetCSCov( int fd, int sendcov, int recvcov );
 struct virtual_socket_t
 {
     void *p_sys;
+    int (*pf_recv_pending) ( void * );
     int (*pf_recv) ( void *, void *, size_t );
     int (*pf_send) ( void *, const void *, size_t );
 };
diff --git a/modules/misc/gnutls.c b/modules/misc/gnutls.c
index e401935..a90211b 100644
--- a/modules/misc/gnutls.c
+++ b/modules/misc/gnutls.c
@@ -212,6 +212,14 @@ static int gnutls_Recv (void *opaque, void *buf, size_t length)
     return (val < 0) ? gnutls_Error (session, val) : val;
 }
 
+static int gnutls_Pending (void *opaque)
+{
+    vlc_tls_t *session = opaque;
+    vlc_tls_sys_t *sys = session->sys;
+
+    int val = gnutls_record_check_pending( sys->session );
+    return (val < 0) ? gnutls_Error (session, val) : val;
+}
 
 /**
  * Starts or continues the TLS handshake.
@@ -496,6 +504,7 @@ static int gnutls_SessionOpen (vlc_tls_creds_t *crd, vlc_tls_t *session,
     session->sock.p_sys = session;
     session->sock.pf_send = gnutls_Send;
     session->sock.pf_recv = gnutls_Recv;
+    session->sock.pf_recv_pending = gnutls_Pending;
     session->handshake = crd->sys->handshake;
     sys->handshaked = false;
 
diff --git a/src/network/io.c b/src/network/io.c
index 7cc9764..d9ac170 100644
--- a/src/network/io.c
+++ b/src/network/io.c
@@ -267,6 +267,15 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
 
     while (i_buflen > 0)
     {
+        /* check virtual socket buffer */
+        if ( vs != NULL && vs->pf_recv_pending
+             && ( vs->pf_recv_pending(vs->p_sys) > 0 )
+           )
+        {
+            /* has still data in its own buffer, won't appear on fd */
+            goto socketread;
+        }
+
         if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) < 0)
         {
             if (errno != EINTR)
@@ -304,6 +313,7 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
 #if defined(WIN32)
         int error;
 #endif
+socketread:
         if (vs != NULL)
         {
             int canc = vlc_savecancel ();
-- 
1.8.1.4




More information about the vlc-devel mailing list