This is a somewhat risky patch, but it has been intended for quite some time:
Remove the libevent handler for write events, only use one common event handler for both reading and writing.
This commit is contained in:
parent
3fdbccb028
commit
abd097acf0
|
@ -226,7 +226,7 @@ int handle_net_write(struct user* user)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void net_event(int fd, short ev, void *arg)
|
void net_event(int fd, short ev, void *arg)
|
||||||
{
|
{
|
||||||
struct user* user = (struct user*) arg;
|
struct user* user = (struct user*) arg;
|
||||||
int flag_close = 0;
|
int flag_close = 0;
|
||||||
|
@ -307,11 +307,8 @@ static void prepare_user_net(struct hub_info* hub, struct user* user)
|
||||||
net_set_nosigpipe(fd, 1);
|
net_set_nosigpipe(fd, 1);
|
||||||
|
|
||||||
event_set(user->net.ev_read, fd, EV_READ | EV_PERSIST, net_event, user);
|
event_set(user->net.ev_read, fd, EV_READ | EV_PERSIST, net_event, user);
|
||||||
event_set(user->net.ev_write, fd, EV_WRITE, net_event, user);
|
|
||||||
event_base_set(hub->evbase, user->net.ev_read);
|
event_base_set(hub->evbase, user->net.ev_read);
|
||||||
event_base_set(hub->evbase, user->net.ev_write);
|
|
||||||
event_add(user->net.ev_read, &timeout);
|
event_add(user->net.ev_read, &timeout);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void net_on_accept(int server_fd, short ev, void *arg)
|
void net_on_accept(int server_fd, short ev, void *arg)
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
*/
|
*/
|
||||||
extern void net_on_accept(int fd, short ev, void *arg);
|
extern void net_on_accept(int fd, short ev, void *arg);
|
||||||
|
|
||||||
|
extern void net_event(int fd, short ev, void *arg);
|
||||||
|
|
||||||
extern int handle_net_read(struct user* user);
|
extern int handle_net_read(struct user* user);
|
||||||
extern int handle_net_write(struct user* user);
|
extern int handle_net_write(struct user* user);
|
||||||
|
|
||||||
|
|
17
src/user.c
17
src/user.c
|
@ -46,13 +46,11 @@ struct user* user_create(struct hub_info* hub, int sd)
|
||||||
if (user == NULL)
|
if (user == NULL)
|
||||||
return NULL; /* OOM */
|
return NULL; /* OOM */
|
||||||
|
|
||||||
user->net.ev_write = hub_malloc_zero(sizeof(struct event));
|
|
||||||
user->net.ev_read = hub_malloc_zero(sizeof(struct event));
|
user->net.ev_read = hub_malloc_zero(sizeof(struct event));
|
||||||
|
|
||||||
if (!user->net.ev_write || !user->net.ev_read)
|
if (!user->net.ev_read)
|
||||||
{
|
{
|
||||||
hub_free(user->net.ev_read);
|
hub_free(user->net.ev_read);
|
||||||
hub_free(user->net.ev_write);
|
|
||||||
hub_free(user);
|
hub_free(user);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -71,13 +69,6 @@ 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->net.ev_write)
|
|
||||||
{
|
|
||||||
event_del(user->net.ev_write);
|
|
||||||
hub_free(user->net.ev_write);
|
|
||||||
user->net.ev_write = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user->net.ev_read)
|
if (user->net.ev_read)
|
||||||
{
|
{
|
||||||
event_del(user->net.ev_read);
|
event_del(user->net.ev_read);
|
||||||
|
@ -344,9 +335,10 @@ 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 && user->net.ev_write)
|
if (user && user->net.ev_read)
|
||||||
{
|
{
|
||||||
event_add(user->net.ev_write, 0);
|
event_set(user->net.ev_read, user->net.sd, EV_READ | EV_WRITE | EV_PERSIST, net_event, user);
|
||||||
|
event_add(user->net.ev_read, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,6 +350,7 @@ void user_net_io_want_read(struct user* user, int timeout_s)
|
||||||
struct timeval timeout = { timeout_s, 0 };
|
struct timeval timeout = { timeout_s, 0 };
|
||||||
if (user && user->net.ev_read)
|
if (user && user->net.ev_read)
|
||||||
{
|
{
|
||||||
|
event_set(user->net.ev_read, user->net.sd, EV_READ | EV_PERSIST, net_event, user);
|
||||||
event_add(user->net.ev_read, &timeout);
|
event_add(user->net.ev_read, &timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,6 @@ struct user_net_io
|
||||||
{
|
{
|
||||||
int sd; /** socket descriptor */
|
int sd; /** socket descriptor */
|
||||||
struct event* ev_read; /** libevent struct for read events */
|
struct event* ev_read; /** libevent struct for read events */
|
||||||
struct event* ev_write; /** libevent struct for write events */
|
|
||||||
|
|
||||||
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