[glib] gsocket: avoid unnecessary select in _send_messages() and _receive_message()



commit fd789f118741d89df348ba21ddc1d813da02fb76
Author: Tim-Philipp Müller <tim centricular com>
Date:   Wed Jun 3 13:06:24 2015 +0100

    gsocket: avoid unnecessary select in _send_messages() and _receive_message()
    
    For performance reasons we should always try to send or
    receive our messages first and only wait for more space
    or data to become available if we get an EAGAIN (and
    are in blocking mode).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751122

 gio/gsocket.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/gio/gsocket.c b/gio/gsocket.c
index 7278e80..7d6e91d 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -4188,11 +4188,6 @@ g_socket_send_messages (GSocket        *socket,
       {
         gint ret;
 
-        if (socket->priv->blocking &&
-            !g_socket_condition_wait (socket,
-                                      G_IO_OUT, cancellable, error))
-          return -1;
-
         ret = sendmmsg (socket->priv->fd, msgvec + num_sent, num_messages - num_sent,
                         flags | G_SOCKET_DEFAULT_SEND_FLAGS);
 
@@ -4206,7 +4201,13 @@ g_socket_send_messages (GSocket        *socket,
             if (socket->priv->blocking &&
                 (errsv == EWOULDBLOCK ||
                  errsv == EAGAIN))
-              continue;
+              {
+                if (!g_socket_condition_wait (socket,
+                                              G_IO_OUT, cancellable, error))
+                  return -1;
+
+                continue;
+              }
 
             if (num_sent > 0 &&
                 (errsv == EWOULDBLOCK ||
@@ -4517,11 +4518,6 @@ g_socket_receive_message (GSocket                 *socket,
     /* do it */
     while (1)
       {
-       if (socket->priv->blocking &&
-           !g_socket_condition_wait (socket,
-                                     G_IO_IN, cancellable, error))
-         return -1;
-
        result = recvmsg (socket->priv->fd, &msg, msg.msg_flags);
 #ifdef MSG_CMSG_CLOEXEC        
        if (result < 0 && get_socket_errno () == EINVAL)
@@ -4542,7 +4538,13 @@ g_socket_receive_message (GSocket                 *socket,
            if (socket->priv->blocking &&
                (errsv == EWOULDBLOCK ||
                 errsv == EAGAIN))
-             continue;
+             {
+               if (!g_socket_condition_wait (socket,
+                                             G_IO_IN, cancellable, error))
+                 return -1;
+
+               continue;
+             }
 
            g_set_error (error, G_IO_ERROR,
                         socket_io_error_from_errno (errsv),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]