diff --git a/src/network/backend.c b/src/network/backend.c index 00cc72d..ac33c33 100644 --- a/src/network/backend.c +++ b/src/network/backend.c @@ -159,8 +159,8 @@ void net_con_initialize(struct net_connection* con, int sd, net_connection_cb ca { g_backend->handler.con_init(g_backend->data, con, sd, callback, ptr); - net_set_nonblocking(con->sd, 1); - net_set_nosigpipe(con->sd, 1); + net_set_nonblocking(net_con_get_sd(con), 1); + net_set_nosigpipe(net_con_get_sd(con), 1); g_backend->handler.con_add(g_backend->data, con, events); g_backend->common.num++; diff --git a/src/network/connection.c b/src/network/connection.c index 9bc8ecf..af4dbca 100644 --- a/src/network/connection.c +++ b/src/network/connection.c @@ -526,3 +526,34 @@ static void net_connect_callback(struct net_connect_handle* handle, enum net_con // Cleanup net_connect_destroy(handle); } + +static void timeout_callback(struct timeout_evt* evt) +{ + net_con_callback((struct net_connection*) evt->ptr, NET_EVENT_TIMEOUT); +} + + +void net_con_set_timeout(struct net_connection* con, int seconds) +{ + if (!con->timeout) + { + con->timeout = hub_malloc_zero(sizeof(struct timeout_evt)); + timeout_evt_initialize(con->timeout, timeout_callback, con); + timeout_queue_insert(net_backend_get_timeout_queue(), con->timeout, seconds); + } + else + { + timeout_queue_reschedule(net_backend_get_timeout_queue(), con->timeout, seconds); + } +} + +void net_con_clear_timeout(struct net_connection* con) +{ + if (con->timeout && timeout_evt_is_scheduled(con->timeout)) + { + timeout_queue_remove(net_backend_get_timeout_queue(), con->timeout); + hub_free(con->timeout); + con->timeout = 0; + } +} + diff --git a/src/network/timer.c b/src/network/timer.c index 23f7100..36d4fda 100644 --- a/src/network/timer.c +++ b/src/network/timer.c @@ -20,31 +20,4 @@ #include "uhub.h" #include "network/connection.h" -static void timeout_callback(struct timeout_evt* evt) -{ - net_con_callback((struct net_connection*) evt->ptr, NET_EVENT_TIMEOUT); -} -void net_con_set_timeout(struct net_connection* con, int seconds) -{ - if (!con->timeout) - { - con->timeout = hub_malloc_zero(sizeof(struct timeout_evt)); - timeout_evt_initialize(con->timeout, timeout_callback, con); - timeout_queue_insert(net_backend_get_timeout_queue(), con->timeout, seconds); - } - else - { - timeout_queue_reschedule(net_backend_get_timeout_queue(), con->timeout, seconds); - } -} - -void net_con_clear_timeout(struct net_connection* con) -{ - if (con->timeout && timeout_evt_is_scheduled(con->timeout)) - { - timeout_queue_remove(net_backend_get_timeout_queue(), con->timeout); - hub_free(con->timeout); - con->timeout = 0; - } -}