gsocket: Fix g_socket_send_messages_with_timeout() on win32

Commit a0cefc2217 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
This commit is contained in:
Philip Withnall 2015-10-05 10:19:50 +01:00
parent f91d1a2a76
commit 212b0c28cc

View File

@ -159,6 +159,17 @@ g_socket_receive_messages_with_timeout (GSocket *socket,
gint64 timeout, gint64 timeout,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); 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 static gint
g_socket_send_messages_with_timeout (GSocket *socket, g_socket_send_messages_with_timeout (GSocket *socket,
GOutputMessage *messages, GOutputMessage *messages,
@ -4094,9 +4105,29 @@ g_socket_send_message (GSocket *socket,
gint flags, gint flags,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) 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; GOutputVector one_vector;
char zero; char zero;
gint64 start_time;
g_return_val_if_fail (G_IS_SOCKET (socket), -1); g_return_val_if_fail (G_IS_SOCKET (socket), -1);
g_return_val_if_fail (address == NULL || G_IS_SOCKET_ADDRESS (address), -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 (cancellable == NULL || G_IS_CANCELLABLE (cancellable), -1);
g_return_val_if_fail (error == NULL || *error == NULL, -1); g_return_val_if_fail (error == NULL || *error == NULL, -1);
start_time = g_get_monotonic_time ();
if (!check_socket (socket, error)) if (!check_socket (socket, error))
return -1; return -1;
@ -4172,12 +4205,12 @@ g_socket_send_message (GSocket *socket,
if (errsv == EINTR) if (errsv == EINTR)
continue; continue;
if (socket->priv->blocking && if (timeout != 0 &&
(errsv == EWOULDBLOCK || (errsv == EWOULDBLOCK ||
errsv == EAGAIN)) errsv == EAGAIN))
{ {
if (!g_socket_condition_wait (socket, if (!block_on_timeout (socket, G_IO_OUT, timeout, start_time,
G_IO_OUT, cancellable, error)) cancellable, error))
return -1; return -1;
continue; continue;
@ -4253,10 +4286,10 @@ g_socket_send_message (GSocket *socket,
{ {
win32_unset_event_mask (socket, FD_WRITE); win32_unset_event_mask (socket, FD_WRITE);
if (socket->priv->blocking) if (timeout != 0)
{ {
if (!g_socket_condition_wait (socket, if (!block_on_timeout (socket, G_IO_OUT, timeout,
G_IO_OUT, cancellable, error)) start_time, cancellable, error))
return -1; return -1;
continue; continue;