mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-30 05:43:28 +02:00
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
This commit is contained in:
@@ -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),
|
||||
|
Reference in New Issue
Block a user