From 212b0c28cc54f0a877a17bbeb70e6d013ad96ff7 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 5 Oct 2015 10:19:50 +0100 Subject: [PATCH] gsocket: Fix g_socket_send_messages_with_timeout() on win32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit a0cefc2217adafb6a21d87b66115df6abc9a9cdd introduced an unresolved symbol, g_socket_send_message_with_timeout(), on win32. Windows unfortunately isn’t clever enough to fill in the gaps and magic up the implementation of that function from nowhere, so we had better do it ourselves. Factor the blocking behaviour out of g_socket_send_message() into a new internal g_socket_send_message_with_timeout(). https://bugzilla.gnome.org/show_bug.cgi?id=756054 --- gio/gsocket.c | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/gio/gsocket.c b/gio/gsocket.c index b80f803e5..2a1050fed 100644 --- a/gio/gsocket.c +++ b/gio/gsocket.c @@ -159,6 +159,17 @@ g_socket_receive_messages_with_timeout (GSocket *socket, gint64 timeout, GCancellable *cancellable, GError **error); +static gssize +g_socket_send_message_with_timeout (GSocket *socket, + GSocketAddress *address, + GOutputVector *vectors, + gint num_vectors, + GSocketControlMessage **messages, + gint num_messages, + gint flags, + gint64 timeout, + GCancellable *cancellable, + GError **error); static gint g_socket_send_messages_with_timeout (GSocket *socket, GOutputMessage *messages, @@ -4094,9 +4105,29 @@ g_socket_send_message (GSocket *socket, gint flags, GCancellable *cancellable, GError **error) +{ + return g_socket_send_message_with_timeout (socket, address, + vectors, num_vectors, + messages, num_messages, flags, + socket->priv->blocking ? -1 : 0, + cancellable, error); +} + +static gssize +g_socket_send_message_with_timeout (GSocket *socket, + GSocketAddress *address, + GOutputVector *vectors, + gint num_vectors, + GSocketControlMessage **messages, + gint num_messages, + gint flags, + gint64 timeout, + GCancellable *cancellable, + GError **error) { GOutputVector one_vector; char zero; + gint64 start_time; g_return_val_if_fail (G_IS_SOCKET (socket), -1); g_return_val_if_fail (address == NULL || G_IS_SOCKET_ADDRESS (address), -1); @@ -4105,6 +4136,8 @@ g_socket_send_message (GSocket *socket, g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), -1); g_return_val_if_fail (error == NULL || *error == NULL, -1); + start_time = g_get_monotonic_time (); + if (!check_socket (socket, error)) return -1; @@ -4172,12 +4205,12 @@ g_socket_send_message (GSocket *socket, if (errsv == EINTR) continue; - if (socket->priv->blocking && + if (timeout != 0 && (errsv == EWOULDBLOCK || errsv == EAGAIN)) { - if (!g_socket_condition_wait (socket, - G_IO_OUT, cancellable, error)) + if (!block_on_timeout (socket, G_IO_OUT, timeout, start_time, + cancellable, error)) return -1; continue; @@ -4253,10 +4286,10 @@ g_socket_send_message (GSocket *socket, { win32_unset_event_mask (socket, FD_WRITE); - if (socket->priv->blocking) + if (timeout != 0) { - if (!g_socket_condition_wait (socket, - G_IO_OUT, cancellable, error)) + if (!block_on_timeout (socket, G_IO_OUT, timeout, + start_time, cancellable, error)) return -1; continue;