Reworking the libevent handling to have only one event handle per file descriptor.

This should be a speed improvement in any case, and might also be
the cause for bug #0000016: Hubsoft locks up at around 60 users
This commit is contained in:
Jan Vidar Krey 2009-03-25 17:56:47 +01:00
parent ae017af758
commit 97b53a99fb
6 changed files with 29 additions and 41 deletions

View File

@ -146,8 +146,8 @@ int hub_handle_support(struct user* u, struct adc_message* cmd)
if (ok) if (ok)
{ {
hub_send_handshake(u); hub_send_handshake(u);
if (u->ev_read) if (u->ev_handle)
event_add(u->ev_read, &timeout); event_add(u->ev_handle, &timeout);
} }
else else
{ {

View File

@ -71,8 +71,8 @@ void on_login_success(struct user* u)
hub_send_motd(u); hub_send_motd(u);
/* reset to idle timeout */ /* reset to idle timeout */
if (u->ev_read) if (u->ev_handle)
event_add(u->ev_read, &timeout); event_add(u->ev_handle, &timeout);
} }
void on_login_failure(struct user* u, enum status_message msg) void on_login_failure(struct user* u, enum status_message msg)

View File

@ -149,18 +149,18 @@ void net_on_read(int fd, short ev, void *arg)
if (user_is_logged_in(user)) if (user_is_logged_in(user))
{ {
if (user->ev_read) if (user->ev_handle)
{ {
struct timeval timeout = { TIMEOUT_IDLE, 0 }; struct timeval timeout = { TIMEOUT_IDLE, 0 };
event_add(user->ev_read, &timeout); event_add(user->ev_handle, &timeout);
} }
} }
else if (user_is_connecting(user)) else if (user_is_connecting(user))
{ {
if (user->ev_read) if (user->ev_handle)
{ {
struct timeval timeout = { TIMEOUT_HANDSHAKE, 0 }; 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 else
{ {
if (user->send_queue_size > 0 && user->ev_write) if (user->send_queue_size > 0 && user->ev_handle)
event_add(user->ev_write, NULL); 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_nonblocking(fd, 1);
net_set_nosigpipe(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_handle, 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_handle);
event_base_set(hub->evbase, user->ev_read); event_add(user->ev_handle, &timeout);
event_base_set(hub->evbase, user->ev_write);
event_add(user->ev_read, &timeout);
} }
} }

View File

@ -135,8 +135,8 @@ int route_to_user(struct user* user, struct adc_message* msg)
{ {
queue_command(user, msg, ret); queue_command(user, msg, ret);
if (user->send_queue_size && user->ev_write) if (user->send_queue_size && user->ev_handle)
event_add(user->ev_write, NULL); event_add(user->ev_handle, NULL);
} }
else else
{ {
@ -158,8 +158,8 @@ int route_to_user(struct user* user, struct adc_message* msg)
{ {
/* queue command */ /* queue command */
queue_command(user, msg, 0); queue_command(user, msg, 0);
if (user->ev_write) if (user->ev_handle)
event_add(user->ev_write, NULL); event_add(user->ev_handle, NULL);
} }
else else

View File

@ -30,13 +30,11 @@ struct user* user_create(struct hub_info* hub, int sd)
if (user == NULL) if (user == NULL)
return NULL; /* OOM */ return NULL; /* OOM */
user->ev_write = hub_malloc_zero(sizeof(struct event)); user->ev_handle = hub_malloc_zero(sizeof(struct event));
user->ev_read = 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_handle);
hub_free(user->ev_write);
hub_free(user); hub_free(user);
return NULL; return NULL;
} }
@ -65,18 +63,11 @@ void user_destroy(struct user* user)
{ {
hub_log(log_trace, "user_destroy(), user=%p", user); hub_log(log_trace, "user_destroy(), user=%p", user);
if (user->ev_write) if (user->ev_handle)
{ {
event_del(user->ev_write); event_del(user->ev_handle);
hub_free(user->ev_write); hub_free(user->ev_handle);
user->ev_write = 0; user->ev_handle = 0;
}
if (user->ev_read)
{
event_del(user->ev_read);
hub_free(user->ev_read);
user->ev_read = 0;
} }
net_close(user->sd); net_close(user->sd);
@ -213,11 +204,11 @@ void user_disconnect(struct user* user, int reason)
} }
/* dont read more data from this user */ /* dont read more data from this user */
if (user->ev_read) if (user->ev_handle)
{ {
event_del(user->ev_read); event_del(user->ev_handle);
hub_free(user->ev_read); hub_free(user->ev_handle);
user->ev_read = 0; user->ev_handle = 0;
} }
hub_log(log_trace, "user_disconnect(), user=%p, reason=%d, state=%d", user, reason, user->state); hub_log(log_trace, "user_disconnect(), user=%p, reason=%d, state=%d", user, reason, user->state);

View File

@ -99,8 +99,7 @@ struct user_counts
struct user struct user
{ {
int sd; /** socket descriptor */ int sd; /** socket descriptor */
struct event* ev_read; /** libevent struct for read events */ struct event* ev_handle;
struct event* ev_write; /** libevent struct for write events */
enum user_state state; /** see enum user_state */ enum user_state state; /** see enum user_state */
enum user_credentials credentials; /** see enum user_credentials */ enum user_credentials credentials; /** see enum user_credentials */
struct user_info id; /** Contains nick name and CID */ struct user_info id; /** Contains nick name and CID */