gsocket: Fix error behaviour of g_socket_send_messages()

If an error in the underlying sendmmsg() syscall occurs after
successfully sending one or more messages, g_socket_send_messages()
should return the number of messages successfully sent, rather than an
error. This mirrors the documented sendmmsg() behaviour.

This is a slight behaviour change for g_socket_send_messages(), but as
it relaxes the error reporting (reporting errors in fewer situations
than before), it should not cause problems.

https://bugzilla.gnome.org/show_bug.cgi?id=751924
This commit is contained in:
Philip Withnall
2015-08-17 18:10:43 +01:00
parent f62cbfc022
commit 1086507e75
2 changed files with 30 additions and 23 deletions

View File

@@ -703,14 +703,31 @@ test_ip_sync_dgram (GSocketFamily family)
m[1].bytes_sent = 0;
m[2].bytes_sent = 0;
/* now try to generate an error by omitting the destination address on [1] */
/* now try to generate an early return by omitting the destination address on [1] */
m[1].address = NULL;
len = g_socket_send_messages (client, m, G_N_ELEMENTS (m), 0, NULL, &error);
g_assert_no_error (error);
g_assert_cmpint (len, ==, 1);
g_assert_cmpint (m[0].bytes_sent, ==, 3);
g_assert_cmpint (m[1].bytes_sent, ==, 0);
g_assert_cmpint (m[2].bytes_sent, ==, 0);
/* reset since we're re-using the message structs */
m[0].bytes_sent = 0;
m[1].bytes_sent = 0;
m[2].bytes_sent = 0;
/* now try to generate an error by omitting all destination addresses */
m[0].address = NULL;
m[1].address = NULL;
m[2].address = NULL;
len = g_socket_send_messages (client, m, G_N_ELEMENTS (m), 0, NULL, &error);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
g_clear_error (&error);
g_assert_cmpint (len, ==, -1);
g_assert_cmpint (m[0].bytes_sent, ==, 3);
g_assert_cmpint (m[0].bytes_sent, ==, 0);
g_assert_cmpint (m[1].bytes_sent, ==, 0);
g_assert_cmpint (m[2].bytes_sent, ==, 0);