Started using the new connection abstraction.

This commit is contained in:
Jan Vidar Krey 2009-08-02 21:46:57 +02:00
parent 653cfb285e
commit cfb8a9f322
6 changed files with 14 additions and 31 deletions

View File

@ -443,7 +443,7 @@ const char* acl_password_generate_challenge(struct acl_handle* acl, struct hub_u
uint64_t tiger_res[3];
static char tiger_buf[MAX_CID_LEN+1];
snprintf(buf, 32, "%d%d%d", (int) user->net.tm_connected, (int) user->id.sid, (int) user->net.sd);
snprintf(buf, 32, "%d%d%d", (int) user->net.tm_connected, (int) user->id.sid, (int) user->net.connection.sd);
tiger((uint64_t*) buf, strlen(buf), (uint64_t*) tiger_res);
base32_encode((unsigned char*) tiger_res, TIGERSIZE, tiger_buf);

View File

@ -978,7 +978,7 @@ void hub_disconnect_user(struct hub_info* hub, struct hub_user* user, int reason
}
/* stop reading from user */
net_shutdown_r(user->net.sd);
net_shutdown_r(user->net.connection.sd);
LOG_TRACE("hub_disconnect_user(), user=%p, reason=%d, state=%d", user, reason, user->state);

View File

@ -26,7 +26,7 @@ extern struct hub_info* g_hub;
#ifdef DEBUG_SENDQ
void debug_sendq_send(struct hub_user* user, int sent, int total)
{
LOG_DUMP("SEND: sd=%d, %d/%d bytes\n", user->net.sd, sent, total);
LOG_DUMP("SEND: sd=%d, %d/%d bytes\n", user->net.connection.sd, sent, total);
if (sent == -1)
{
int err = net_error();
@ -55,7 +55,7 @@ void debug_sendq_recv(struct hub_user* user, int received, int max, const char*
int net_user_send(void* ptr, const void* buf, size_t len)
{
struct hub_user* user = (struct hub_user*) ptr;
int ret = net_send(user->net.sd, buf, len, UHUB_SEND_SIGNAL);
int ret = net_send(user->net.connection.sd, buf, len, UHUB_SEND_SIGNAL);
#ifdef DEBUG_SENDQ
debug_sendq_send(user, ret, len);
#endif
@ -103,7 +103,7 @@ int net_user_send_ssl(void* ptr, const void* buf, size_t len)
int net_user_recv(void* ptr, void* buf, size_t len)
{
struct hub_user* user = (struct hub_user*) ptr;
int ret = net_recv(user->net.sd, buf, len, 0);
int ret = net_recv(user->net.connection.sd, buf, len, 0);
if (ret > 0)
{
user_reset_last_read(user);
@ -274,7 +274,7 @@ void net_event(int fd, short ev, void *arg)
static void prepare_user_net(struct hub_info* hub, struct hub_user* user)
{
int fd = user->net.sd;
int fd = user->net.connection.sd;
#ifdef SET_SENDBUG
size_t sendbuf = 0;

View File

@ -46,14 +46,11 @@ struct hub_user* user_create(struct hub_info* hub, int sd)
if (user == NULL)
return NULL; /* OOM */
user->net.sd = sd;
user->net.tm_connected = time(NULL);
user->net.send_queue = hub_sendq_create();
user->net.recv_queue = hub_recvq_create();
event_set(&user->net.event, sd, EV_READ | EV_PERSIST, net_event, user);
event_base_set(hub->evbase, &user->net.event);
event_add(&user->net.event, 0);
net_con_initialize(&user->net.connection, sd, user, EV_READ);
evtimer_set(&user->net.timeout, net_event, user);
event_base_set(hub->evbase, &user->net.timeout);
@ -69,13 +66,12 @@ void user_destroy(struct hub_user* user)
{
LOG_TRACE("user_destroy(), user=%p", user);
event_del(&user->net.event);
net_con_close(&user->net.connection);
evtimer_del(&user->net.timeout);
hub_recvq_destroy(user->net.recv_queue);
hub_sendq_destroy(user->net.send_queue);
net_close(user->net.sd);
adc_msg_free(user->info);
user_clear_feature_cast_support(user);
hub_free(user);
@ -325,11 +321,7 @@ void user_net_io_want_write(struct hub_user* user)
#ifdef DEBUG_SENDQ
LOG_TRACE("user_net_io_want_write: %s (pending: %d)", user_log_str(user), event_pending(&user->net.event, EV_READ | EV_WRITE, 0));
#endif
if (event_pending(&user->net.event, EV_READ | EV_WRITE, 0) == (EV_READ | EV_WRITE))
return;
event_del(&user->net.event);
event_set(&user->net.event, user->net.sd, EV_READ | EV_WRITE | EV_PERSIST, net_event, user);
event_add(&user->net.event, 0);
net_con_update(&user->net.connection, EV_READ | EV_WRITE);
}
void user_net_io_want_read(struct hub_user* user)
@ -337,11 +329,7 @@ void user_net_io_want_read(struct hub_user* user)
#ifdef DEBUG_SENDQ
LOG_TRACE("user_net_io_want_read: %s (pending: %d)", user_log_str(user), event_pending(&user->net.event, EV_READ | EV_WRITE, 0));
#endif
if (event_pending(&user->net.event, EV_READ | EV_WRITE, 0) == EV_READ)
return;
event_del(&user->net.event);
event_set(&user->net.event, user->net.sd, EV_READ | EV_PERSIST, net_event, user);
event_add(&user->net.event, 0);
net_con_update(&user->net.connection, EV_READ);
}
void user_reset_last_write(struct hub_user* user)

View File

@ -95,20 +95,14 @@ struct hub_user_limits
struct hub_user_net_io
{
int sd; /** socket descriptor */
struct event event; /** libevent struct for read/write events */
struct net_connection connection; /** Connection data */
struct event timeout; /** timeout handling */
struct hub_recvq* recv_queue;
struct hub_sendq* send_queue;
time_t tm_connected; /** time when user connected */
time_t tm_last_read; /** time the user last received something from the hub */
time_t tm_last_write; /** time the user last sent something to the hub */
struct ip_addr_encap ipaddr; /** IP address of connected user */
#ifdef SSL_SUPPORT
SSL* ssl; /** SSL handle */
#endif /* SSL_SUPPORT */
};
struct hub_user

View File

@ -46,6 +46,7 @@ void net_con_close(struct net_connection* con)
if (!event_pending(&con->event, EV_READ | EV_WRITE, 0))
return;
event_del(&con->event);
net_close(con->sd);
con->sd = -1;
}