No need to store event mask in the user object since libevent already does it for us.

This commit is contained in:
Jan Vidar Krey 2009-07-25 03:26:59 +02:00
parent 0ec4913e15
commit dc90245ade
2 changed files with 5 additions and 11 deletions

View File

@ -51,8 +51,7 @@ struct user* user_create(struct hub_info* hub, int sd)
user->net.send_queue = hub_sendq_create();
user->net.recv_queue = hub_recvq_create();
user->net.events = EV_READ;
event_set(&user->net.event, sd, user->net.events | EV_PERSIST, net_event, user);
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);
@ -333,11 +332,10 @@ void user_net_io_want_write(struct user* user)
#ifdef DEBUG_SENDQ
hub_log(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 (user->net.events == (EV_READ | EV_WRITE))
if (event_pending(&user->net.event, EV_READ | EV_WRITE, 0) == (EV_READ | EV_WRITE))
return;
user->net.events = (EV_READ | EV_WRITE);
event_del(&user->net.event);
event_set(&user->net.event, user->net.sd, user->net.events | EV_PERSIST, net_event, user);
event_set(&user->net.event, user->net.sd, EV_READ | EV_WRITE | EV_PERSIST, net_event, user);
event_add(&user->net.event, 0);
}
@ -346,11 +344,10 @@ void user_net_io_want_read(struct user* user)
#ifdef DEBUG_SENDQ
hub_log(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 (user->net.events == EV_READ)
if (event_pending(&user->net.event, EV_READ | EV_WRITE, 0) == EV_READ)
return;
user->net.events = EV_READ;
event_del(&user->net.event);
event_set(&user->net.event, user->net.sd, user->net.events | EV_PERSIST, net_event, user);
event_set(&user->net.event, user->net.sd, EV_READ | EV_PERSIST, net_event, user);
event_add(&user->net.event, 0);
}

View File

@ -97,11 +97,8 @@ struct user_net_io
int sd; /** socket descriptor */
struct event event; /** libevent struct for read/write events */
struct event timeout; /** timeout handling */
int events; /** currently set events, used to reduce event_{add,del,set} calls */
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 */