Fix shutdown problem and reduce event_{add,del,set} calls.
This commit is contained in:
parent
b02618d19c
commit
5f0c84f46a
14
src/user.c
14
src/user.c
@ -51,7 +51,8 @@ struct user* user_create(struct hub_info* hub, int sd)
|
|||||||
user->net.send_queue = hub_sendq_create();
|
user->net.send_queue = hub_sendq_create();
|
||||||
user->net.recv_queue = hub_recvq_create();
|
user->net.recv_queue = hub_recvq_create();
|
||||||
|
|
||||||
event_set(&user->net.event, sd, EV_READ | EV_PERSIST, net_event, user);
|
user->net.events = EV_READ;
|
||||||
|
event_set(&user->net.event, sd, user->net.events | EV_PERSIST, net_event, user);
|
||||||
event_base_set(hub->evbase, &user->net.event);
|
event_base_set(hub->evbase, &user->net.event);
|
||||||
event_add(&user->net.event, 0);
|
event_add(&user->net.event, 0);
|
||||||
|
|
||||||
@ -71,6 +72,7 @@ void user_destroy(struct user* user)
|
|||||||
hub_log(log_trace, "user_destroy(), user=%p", user);
|
hub_log(log_trace, "user_destroy(), user=%p", user);
|
||||||
|
|
||||||
event_del(&user->net.event);
|
event_del(&user->net.event);
|
||||||
|
evtimer_del(&user->net.timeout);
|
||||||
|
|
||||||
hub_recvq_destroy(user->net.recv_queue);
|
hub_recvq_destroy(user->net.recv_queue);
|
||||||
hub_sendq_destroy(user->net.send_queue);
|
hub_sendq_destroy(user->net.send_queue);
|
||||||
@ -331,8 +333,11 @@ void user_net_io_want_write(struct user* user)
|
|||||||
#ifdef DEBUG_SENDQ
|
#ifdef DEBUG_SENDQ
|
||||||
hub_log(log_trace, "user_net_io_want_write: %s", user_log_str(user));
|
hub_log(log_trace, "user_net_io_want_write: %s", user_log_str(user));
|
||||||
#endif
|
#endif
|
||||||
|
if (user->net.events == (EV_READ | EV_WRITE))
|
||||||
|
return;
|
||||||
|
user->net.events = (EV_READ | EV_WRITE);
|
||||||
event_del(&user->net.event);
|
event_del(&user->net.event);
|
||||||
event_set(&user->net.event, user->net.sd, EV_READ | EV_WRITE | EV_PERSIST, net_event, user);
|
event_set(&user->net.event, user->net.sd, user->net.events | EV_PERSIST, net_event, user);
|
||||||
event_add(&user->net.event, 0);
|
event_add(&user->net.event, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,8 +346,11 @@ void user_net_io_want_read(struct user* user)
|
|||||||
#ifdef DEBUG_SENDQ
|
#ifdef DEBUG_SENDQ
|
||||||
hub_log(log_trace, "user_net_io_want_read: %s", user_log_str(user));
|
hub_log(log_trace, "user_net_io_want_read: %s", user_log_str(user));
|
||||||
#endif
|
#endif
|
||||||
|
if (user->net.events == EV_READ)
|
||||||
|
return;
|
||||||
|
user->net.events = EV_READ;
|
||||||
event_del(&user->net.event);
|
event_del(&user->net.event);
|
||||||
event_set(&user->net.event, user->net.sd, EV_READ | EV_PERSIST, net_event, user);
|
event_set(&user->net.event, user->net.sd, user->net.events | EV_PERSIST, net_event, user);
|
||||||
event_add(&user->net.event, 0);
|
event_add(&user->net.event, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ struct user_net_io
|
|||||||
int sd; /** socket descriptor */
|
int sd; /** socket descriptor */
|
||||||
struct event event; /** libevent struct for read/write events */
|
struct event event; /** libevent struct for read/write events */
|
||||||
struct event timeout; /** timeout handling */
|
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_recvq* recv_queue;
|
||||||
struct hub_sendq* send_queue;
|
struct hub_sendq* send_queue;
|
||||||
|
Loading…
Reference in New Issue
Block a user