diff --git a/src/core/probe.c b/src/core/probe.c index 4c5f122..f6d7896 100644 --- a/src/core/probe.c +++ b/src/core/probe.c @@ -101,7 +101,7 @@ struct hub_probe* probe_create(struct hub_info* hub, int sd, struct ip_addr_enca return NULL; /* OOM */ probe->hub = hub; - probe->connection = (struct net_connection*) hub_malloc(sizeof(struct net_connection)); + probe->connection = net_con_create(); net_con_initialize(probe->connection, sd, probe_net_event, probe, NET_EVENT_READ); net_con_set_timeout(probe->connection, TIMEOUT_CONNECTED); diff --git a/src/core/user.c b/src/core/user.c index 0213ed6..577020a 100644 --- a/src/core/user.c +++ b/src/core/user.c @@ -39,7 +39,7 @@ struct hub_user* user_create(struct hub_info* hub, struct net_connection* con, s { struct hub_user* user = NULL; - LOG_TRACE("user_create(), hub=%p, con[sd=%d]", hub, con->sd); + LOG_TRACE("user_create(), hub=%p, con[sd=%d]", hub, net_con_get_sd(con)); user = (struct hub_user*) hub_malloc_zero(sizeof(struct hub_user)); diff --git a/src/network/connection-common.c b/src/network/connection-common.c index 3457860..26ed272 100644 --- a/src/network/connection-common.c +++ b/src/network/connection-common.c @@ -16,24 +16,9 @@ /* FIXME: Meant for debugging */ #define NET_EVENT_SET 0x0800 -static inline int net_con_flag_get(struct net_connection* con, unsigned int flag) -{ - return con->flags & flag; -} - -static inline void net_con_flag_set(struct net_connection* con, unsigned int flag) -{ - con->flags |= flag; -} - -static inline void net_con_flag_unset(struct net_connection* con, unsigned int flag) -{ - con->flags &= ~flag; -} - #define NET_CON_STRUCT_BASIC \ int sd; /** socket descriptor */ \ - unsigned int flags; /** Connection flags */ \ + uint32_t flags; /** Connection flags */ \ void* ptr; /** data pointer */ \ net_connection_cb callback; /** Callback function */ \ time_t last_recv; /** Timestamp for last recv() */ \ diff --git a/src/network/connection-libevent.c b/src/network/connection-libevent.c index 63bc0d7..725c7f3 100644 --- a/src/network/connection-libevent.c +++ b/src/network/connection-libevent.c @@ -26,6 +26,42 @@ struct net_connection struct event timeout; /** Used for internal timeout handling */ }; +int net_con_get_sd(struct net_connection* con) +{ + return con->sd; +} + +void* net_con_get_ptr(struct net_connection* con) +{ + return con->ptr; +} + +struct net_connection* net_con_create() +{ + struct net_connection* con = (struct net_connection*) hub_malloc(sizeof(struct net_connection)); + return con; +} + +static inline int net_con_flag_get(struct net_connection* con, unsigned int flag) +{ + return con->flags & flag; +} + +static inline void net_con_flag_set(struct net_connection* con, unsigned int flag) +{ + con->flags |= flag; +} + +static inline void net_con_flag_unset(struct net_connection* con, unsigned int flag) +{ + con->flags &= ~flag; +} + +void net_con_destroy(struct net_connection* con) +{ + hub_free(con); +} + static inline int net_con_convert_to_libevent_mask(int ev) { int events = 0; diff --git a/src/network/connection.h b/src/network/connection.h index 508a236..29c7fa5 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -42,6 +42,7 @@ struct net_timer void* ptr; }; + extern void net_timer_initialize(struct net_timer* timer, net_timeout_cb callback, void* ptr); extern void net_timer_reset(struct net_timer* timer, int seconds); extern void net_timer_shutdown(struct net_timer* timer); @@ -49,6 +50,8 @@ extern void net_timer_shutdown(struct net_timer* timer); extern int net_con_get_sd(struct net_connection* con); extern void* net_con_get_ptr(struct net_connection* con); +extern struct net_connection* net_con_create(); +extern void net_con_destroy(struct net_connection*); extern void net_con_initialize(struct net_connection* con, int sd, net_connection_cb callback, const void* ptr, int events); extern void net_con_reinitialize(struct net_connection* con, net_connection_cb callback, const void* ptr, int events); extern void net_con_update(struct net_connection* con, int events);