host_candidate = NULL;
while (res == HOST_CANDIDATE_CANT_CREATE_SOCKET ||
res == HOST_CANDIDATE_DUPLICATE_PORT) {
- nice_debug ("Agent %p: Trying to create host candidate on port %d", agent, current_port);
+ nice_debug ("Agent %p: Trying to create %s host candidate on port %d", agent,
+ nice_candidate_transport_to_string (transport), current_port);
nice_address_set_port (addr, current_port);
res = discovery_add_local_host_candidate (agent, stream->id, cid,
addr, transport, accept_duplicate, &host_candidate);
nice_candidate_transport_to_string (transport), stream->id,
component->id);
}
+ ret = FALSE;
goto error;
}
NiceStream *stream;
NiceSocket *nicesock = NULL;
HostCandidateResult res = HOST_CANDIDATE_FAILED;
+ GError *error = NULL;
if (!agent_find_component (agent, stream_id, component_id, &stream, &component))
return res;
} else if (transport == NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE) {
nicesock = nice_tcp_active_socket_new (agent->main_context, address);
} else if (transport == NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE) {
- nicesock = nice_tcp_passive_socket_new (agent->main_context, address);
+ nicesock = nice_tcp_passive_socket_new (agent->main_context, address, &error);
} else {
/* TODO: Add TCP-SO */
}
if (!nicesock) {
- res = HOST_CANDIDATE_CANT_CREATE_SOCKET;
+ if (error && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_ADDRESS_IN_USE))
+ res = HOST_CANDIDATE_DUPLICATE_PORT;
+ else
+ res = HOST_CANDIDATE_CANT_CREATE_SOCKET;
+ g_clear_error (&error);
goto errors;
}
static guint nice_address_hash (const NiceAddress * key);
NiceSocket *
-nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr)
+nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr, GError **error)
{
union {
struct sockaddr_storage storage;
/* GSocket: All socket file descriptors are set to be close-on-exec. */
g_socket_set_blocking (gsock, false);
- gret = g_socket_bind (gsock, gaddr, FALSE, NULL) &&
- g_socket_listen (gsock, NULL);
+ gret = g_socket_bind (gsock, gaddr, FALSE, error) &&
+ g_socket_listen (gsock, error);
g_object_unref (gaddr);
if (gret == FALSE) {
G_BEGIN_DECLS
-NiceSocket * nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr);
+NiceSocket * nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr,
+ GError **gerror);
NiceSocket * nice_tcp_passive_socket_accept (NiceSocket *socket);
void nice_tcp_passive_socket_remove_connection (NiceSocket *socket,
agent = nice_agent_new (NULL, NICE_COMPATIBILITY_RFC5245);
- stream1 = nice_agent_add_stream (agent, 1);
+ stream1 = nice_agent_add_stream (agent, 2);
nice_agent_set_port_range (agent, stream1, 1, 8888, 8888);
- nice_agent_gather_candidates (agent, stream1);
+ nice_agent_set_port_range (agent, stream1, 2, 8888, 8888);
+
+ /* First test with ICE-TCP enabled, this should fail on creating the port */
+ g_assert (nice_agent_gather_candidates (agent, stream1) == FALSE);
+
+ /* First test with ICE-TCP disabled, this should fail on our explicit test */
+ g_object_set (agent, "ice-tcp", FALSE, NULL);
+ g_assert (nice_agent_gather_candidates (agent, stream1) == FALSE);
+
+ nice_agent_set_port_range (agent, stream1, 2, 9999, 9999);
+ g_assert (nice_agent_gather_candidates (agent, stream1));
g_object_unref (agent);
WSACleanup();
#endif
return 0;
-}
\ No newline at end of file
+}
{
NiceAddress active_bind_addr, passive_bind_addr;
GSource *srv_listen_source, *srv_input_source, *cli_input_source;
+ GError *error = NULL;
g_networking_init ();
nice_address_init (&tmp);
passive_sock = nice_tcp_passive_socket_new (g_main_loop_get_context (mainloop),
- &passive_bind_addr);
+ &passive_bind_addr, &error);
+ g_assert_no_error (error);
g_assert (passive_sock);
srv_listen_source = g_socket_create_source (passive_sock->fileno,