diff options
author | Fabrice Bellet <fabrice@bellet.info> | 2020-09-26 17:02:12 +0200 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@ocrete.ca> | 2020-12-07 21:52:55 +0000 |
commit | 7ec7f66d4eb52b5f018cf700fd41d18b5666543c (patch) | |
tree | 0265aa70516aaebeac5d0495a31762f2c8aca0c1 /tests | |
parent | cadf5118284ea08ac7db020f741c0772d5d84941 (diff) |
agent: report duplicated port in udp bsd sockets too
This patch fixes cases, where the range is full, some ports fail with
HOST_CANDIDATE_CANT_CREATE_SOCKET, other fail with
HOST_CANDIDATE_DUPLICATE_PORT, the value of res we keep when leaving the
loop is randomly the one of the last iteration of the loop.
CANT_CREATE_SOCKET still happens when trying to create an udp bsd socket
with the same address and port than one of another component, so it is
also a case of duplicate port in fact.
To be homogeneous, we add a gerror for nice_udp_bsd_socket_new(), like
we did in nice_tcp_passive_socket_new(), and we can catch the same
G_IO_ERROR_ADDRESS_IN_USE there too, when failing to get free available
udp ports.
This patch is a complement to merge request !158
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-bsd.c | 33 | ||||
-rw-r--r-- | tests/test-drop-invalid.c | 4 | ||||
-rw-r--r-- | tests/test-socket-is-based-on.c | 4 |
3 files changed, 30 insertions, 11 deletions
diff --git a/tests/test-bsd.c b/tests/test-bsd.c index c182164..6538a2f 100644 --- a/tests/test-bsd.c +++ b/tests/test-bsd.c @@ -61,8 +61,10 @@ static void test_socket_initial_properties (void) { NiceSocket *sock; + GError *error = NULL; - sock = nice_udp_bsd_socket_new (NULL); + sock = nice_udp_bsd_socket_new (NULL, &error); + g_assert_no_error (error); g_assert (sock != NULL); // not bound to a particular interface @@ -78,8 +80,10 @@ test_socket_address_properties (void) { NiceSocket *sock; NiceAddress tmp; + GError *error = NULL; - sock = nice_udp_bsd_socket_new (NULL); + sock = nice_udp_bsd_socket_new (NULL, &error); + g_assert_no_error (error); g_assert (sock != NULL); g_assert (nice_address_set_from_string (&tmp, "127.0.0.1")); @@ -97,11 +101,14 @@ test_simple_send_recv (void) NiceSocket *client; NiceAddress tmp; gchar buf[5]; + GError *error = NULL; - server = nice_udp_bsd_socket_new (NULL); + server = nice_udp_bsd_socket_new (NULL, &error); + g_assert_no_error (error); g_assert (server != NULL); - client = nice_udp_bsd_socket_new (NULL); + client = nice_udp_bsd_socket_new (NULL, &error); + g_assert_no_error (error); g_assert (client != NULL); g_assert (nice_address_set_from_string (&tmp, "127.0.0.1")); @@ -132,8 +139,10 @@ test_zero_send_recv (void) gchar buf[5]; NiceOutputMessage local_out_message; NiceInputMessage local_in_message; + GError *error = NULL; - sock = nice_udp_bsd_socket_new (NULL); + sock = nice_udp_bsd_socket_new (NULL, &error); + g_assert_no_error (error); g_assert (sock != NULL); g_assert (nice_address_set_from_string (&tmp, "127.0.0.1")); @@ -168,11 +177,14 @@ test_multi_buffer_recv (void) NiceAddress tmp; guint8 buf[20]; guint8 dummy_buf[9]; + GError *error = NULL; - server = nice_udp_bsd_socket_new (NULL); + server = nice_udp_bsd_socket_new (NULL, &error); + g_assert_no_error (error); g_assert (server != NULL); - client = nice_udp_bsd_socket_new (NULL); + client = nice_udp_bsd_socket_new (NULL, &error); + g_assert_no_error (error); g_assert (client != NULL); g_assert (nice_address_set_from_string (&tmp, "127.0.0.1")); @@ -239,11 +251,14 @@ test_multi_message_recv (guint n_sends, guint n_receives, NiceSocket *server; NiceSocket *client; NiceAddress tmp; + GError *error = NULL; - server = nice_udp_bsd_socket_new (NULL); + server = nice_udp_bsd_socket_new (NULL, &error); + g_assert_no_error (error); g_assert (server != NULL); - client = nice_udp_bsd_socket_new (NULL); + client = nice_udp_bsd_socket_new (NULL, &error); + g_assert_no_error (error); g_assert (client != NULL); g_assert (nice_address_set_from_string (&tmp, "127.0.0.1")); diff --git a/tests/test-drop-invalid.c b/tests/test-drop-invalid.c index def5b03..a484c2d 100644 --- a/tests/test-drop-invalid.c +++ b/tests/test-drop-invalid.c @@ -419,13 +419,15 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas NiceCandidate *local_cand = NULL; NiceCandidate *remote_cand = NULL; NiceSocket *tmpsock; + GError *error = NULL; g_assert (nice_agent_get_selected_pair (lagent, ls_id, 1, &local_cand, &remote_cand)); g_assert (local_cand); g_assert (remote_cand); - tmpsock = nice_udp_bsd_socket_new (NULL); + tmpsock = nice_udp_bsd_socket_new (NULL, &error); + g_assert_no_error (error); nice_socket_send (tmpsock, &remote_cand->addr, 4, "ABCD"); nice_socket_send (tmpsock, &local_cand->addr, 5, "ABCDE"); nice_socket_free (tmpsock); diff --git a/tests/test-socket-is-based-on.c b/tests/test-socket-is-based-on.c index db48924..17ca5fd 100644 --- a/tests/test-socket-is-based-on.c +++ b/tests/test-socket-is-based-on.c @@ -84,6 +84,7 @@ main (int argc, char *argv[]) GMainLoop *mainloop = NULL; NiceAddress addr; + GError *error = NULL; g_networking_init (); @@ -95,7 +96,8 @@ main (int argc, char *argv[]) nice_address_set_from_string (&addr, "127.0.0.1"); /* Standalone socket */ - udp_bsd = nice_udp_bsd_socket_new (&addr); + udp_bsd = nice_udp_bsd_socket_new (&addr, &error); + g_assert_no_error (error); /* tcp_passive -> pseudossl -> udp_turn_over_tcp */ tcp_active = nice_tcp_active_socket_new (g_main_loop_get_context (mainloop), |