Commit 6fac5903 authored by captainwong's avatar captainwong

update tools

parent b624bcf6
...@@ -264,11 +264,9 @@ void accept_cb(evconnlistener* listener, evutil_socket_t fd, sockaddr* addr, int ...@@ -264,11 +264,9 @@ void accept_cb(evconnlistener* listener, evutil_socket_t fd, sockaddr* addr, int
auto sin = (sockaddr_in*)addr; auto sin = (sockaddr_in*)addr;
inet_ntop(AF_INET, &sin->sin_addr, str, INET_ADDRSTRLEN); inet_ntop(AF_INET, &sin->sin_addr, str, INET_ADDRSTRLEN);
printf("accpet TCP connection #%d from: %s:%d\n", (int)fd, str, sin->sin_port); printf("accpet TCP connection #%d from: %s:%d\n", (int)fd, str, sin->sin_port);
evutil_make_socket_nonblocking(fd); evutil_make_socket_nonblocking(fd);
static int worker_id = 0; static int worker_id = 0;
auto context = worker_thread_contexts[worker_id]; auto context = worker_thread_contexts[worker_id];
auto bev = bufferevent_socket_new(context->base, fd, BEV_OPT_CLOSE_ON_FREE); auto bev = bufferevent_socket_new(context->base, fd, BEV_OPT_CLOSE_ON_FREE);
if (!bev) { if (!bev) {
...@@ -276,6 +274,7 @@ void accept_cb(evconnlistener* listener, evutil_socket_t fd, sockaddr* addr, int ...@@ -276,6 +274,7 @@ void accept_cb(evconnlistener* listener, evutil_socket_t fd, sockaddr* addr, int
event_base_loopbreak(context->base); event_base_loopbreak(context->base);
return; return;
} }
Client client; Client client;
client.fd = (int)fd; client.fd = (int)fd;
client.output = bufferevent_get_output(bev); client.output = bufferevent_get_output(bev);
...@@ -287,7 +286,6 @@ void accept_cb(evconnlistener* listener, evutil_socket_t fd, sockaddr* addr, int ...@@ -287,7 +286,6 @@ void accept_cb(evconnlistener* listener, evutil_socket_t fd, sockaddr* addr, int
bufferevent_setcb(bev, readcb, nullptr, eventcb, context); bufferevent_setcb(bev, readcb, nullptr, eventcb, context);
bufferevent_enable(bev, EV_WRITE | EV_READ); bufferevent_enable(bev, EV_WRITE | EV_READ);
worker_id = (++worker_id) % thread_count; worker_id = (++worker_id) % thread_count;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment