diff --git a/src/hub.c b/src/hub.c index 96b0f89..5ad733e 100644 --- a/src/hub.c +++ b/src/hub.c @@ -146,8 +146,8 @@ int hub_handle_support(struct user* u, struct adc_message* cmd) if (ok) { hub_send_handshake(u); - if (u->ev_read) - event_add(u->ev_read, &timeout); + if (u->ev_handle) + event_add(u->ev_handle, &timeout); } else { diff --git a/src/hubevent.c b/src/hubevent.c index 0ccb273..25d481f 100644 --- a/src/hubevent.c +++ b/src/hubevent.c @@ -71,8 +71,8 @@ void on_login_success(struct user* u) hub_send_motd(u); /* reset to idle timeout */ - if (u->ev_read) - event_add(u->ev_read, &timeout); + if (u->ev_handle) + event_add(u->ev_handle, &timeout); } void on_login_failure(struct user* u, enum status_message msg) diff --git a/src/netevent.c b/src/netevent.c index ef42051..8c0dc38 100644 --- a/src/netevent.c +++ b/src/netevent.c @@ -149,18 +149,18 @@ void net_on_read(int fd, short ev, void *arg) if (user_is_logged_in(user)) { - if (user->ev_read) + if (user->ev_handle) { struct timeval timeout = { TIMEOUT_IDLE, 0 }; - event_add(user->ev_read, &timeout); + event_add(user->ev_handle, &timeout); } } else if (user_is_connecting(user)) { - if (user->ev_read) + if (user->ev_handle) { struct timeval timeout = { TIMEOUT_HANDSHAKE, 0 }; - event_add(user->ev_read, &timeout); + event_add(user->ev_handle, &timeout); } } } @@ -250,8 +250,8 @@ void net_on_write(int fd, short ev, void *arg) } else { - if (user->send_queue_size > 0 && user->ev_write) - event_add(user->ev_write, NULL); + if (user->send_queue_size > 0 && user->ev_handle) + event_add(user->ev_handle, NULL); } } @@ -307,11 +307,9 @@ void net_on_accept(int server_fd, short ev, void *arg) net_set_nonblocking(fd, 1); net_set_nosigpipe(fd, 1); - event_set(user->ev_read, fd, EV_READ | EV_PERSIST, net_on_read, user); - event_set(user->ev_write, fd, EV_WRITE, net_on_write, user); - event_base_set(hub->evbase, user->ev_read); - event_base_set(hub->evbase, user->ev_write); - event_add(user->ev_read, &timeout); + event_set(user->ev_handle, fd, EV_READ | EV_PERSIST, net_on_read, user); + event_base_set(hub->evbase, user->ev_handle); + event_add(user->ev_handle, &timeout); } } diff --git a/src/route.c b/src/route.c index ac0bfe6..cf76aca 100644 --- a/src/route.c +++ b/src/route.c @@ -135,8 +135,8 @@ int route_to_user(struct user* user, struct adc_message* msg) { queue_command(user, msg, ret); - if (user->send_queue_size && user->ev_write) - event_add(user->ev_write, NULL); + if (user->send_queue_size && user->ev_handle) + event_add(user->ev_handle, NULL); } else { @@ -158,8 +158,8 @@ int route_to_user(struct user* user, struct adc_message* msg) { /* queue command */ queue_command(user, msg, 0); - if (user->ev_write) - event_add(user->ev_write, NULL); + if (user->ev_handle) + event_add(user->ev_handle, NULL); } else diff --git a/src/user.c b/src/user.c index 77f0a58..840ccb9 100644 --- a/src/user.c +++ b/src/user.c @@ -30,13 +30,11 @@ struct user* user_create(struct hub_info* hub, int sd) if (user == NULL) return NULL; /* OOM */ - user->ev_write = hub_malloc_zero(sizeof(struct event)); - user->ev_read = hub_malloc_zero(sizeof(struct event)); + user->ev_handle = hub_malloc_zero(sizeof(struct event)); - if (!user->ev_write || !user->ev_read) + if (!user->ev_handle) { - hub_free(user->ev_read); - hub_free(user->ev_write); + hub_free(user->ev_handle); hub_free(user); return NULL; } @@ -65,18 +63,11 @@ void user_destroy(struct user* user) { hub_log(log_trace, "user_destroy(), user=%p", user); - if (user->ev_write) + if (user->ev_handle) { - event_del(user->ev_write); - hub_free(user->ev_write); - user->ev_write = 0; - } - - if (user->ev_read) - { - event_del(user->ev_read); - hub_free(user->ev_read); - user->ev_read = 0; + event_del(user->ev_handle); + hub_free(user->ev_handle); + user->ev_handle = 0; } net_close(user->sd); @@ -213,11 +204,11 @@ void user_disconnect(struct user* user, int reason) } /* dont read more data from this user */ - if (user->ev_read) + if (user->ev_handle) { - event_del(user->ev_read); - hub_free(user->ev_read); - user->ev_read = 0; + event_del(user->ev_handle); + hub_free(user->ev_handle); + user->ev_handle = 0; } hub_log(log_trace, "user_disconnect(), user=%p, reason=%d, state=%d", user, reason, user->state); diff --git a/src/user.h b/src/user.h index 1c97185..a0819b6 100644 --- a/src/user.h +++ b/src/user.h @@ -99,8 +99,7 @@ struct user_counts struct user { int sd; /** socket descriptor */ - struct event* ev_read; /** libevent struct for read events */ - struct event* ev_write; /** libevent struct for write events */ + struct event* ev_handle; enum user_state state; /** see enum user_state */ enum user_credentials credentials; /** see enum user_credentials */ struct user_info id; /** Contains nick name and CID */