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)
{
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
{

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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

View File

@ -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);

View File

@ -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 */