Commit 2764c556 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

src: Code cleanup

parent 30d3ea7c
...@@ -47,9 +47,9 @@ ListenHandler::ListenHandler(event_base *evbase, SSL_CTX *sv_ssl_ctx, ...@@ -47,9 +47,9 @@ ListenHandler::ListenHandler(event_base *evbase, SSL_CTX *sv_ssl_ctx,
sv_ssl_ctx_(sv_ssl_ctx), sv_ssl_ctx_(sv_ssl_ctx),
cl_ssl_ctx_(cl_ssl_ctx), cl_ssl_ctx_(cl_ssl_ctx),
worker_round_robin_cnt_(0), worker_round_robin_cnt_(0),
workers_(0), workers_(nullptr),
num_worker_(0), num_worker_(0),
spdy_(0) spdy_(nullptr)
{} {}
ListenHandler::~ListenHandler() ListenHandler::~ListenHandler()
...@@ -61,7 +61,7 @@ void ListenHandler::create_worker_thread(size_t num) ...@@ -61,7 +61,7 @@ void ListenHandler::create_worker_thread(size_t num)
num_worker_ = 0; num_worker_ = 0;
for(size_t i = 0; i < num; ++i) { for(size_t i = 0; i < num; ++i) {
int rv; int rv;
WorkerInfo *info = &workers_[num_worker_]; auto info = &workers_[num_worker_];
rv = socketpair(AF_UNIX, SOCK_STREAM, 0, info->sv); rv = socketpair(AF_UNIX, SOCK_STREAM, 0, info->sv);
if(rv == -1) { if(rv == -1) {
LLOG(ERROR, this) << "socketpair() failed: errno=" << errno; LLOG(ERROR, this) << "socketpair() failed: errno=" << errno;
...@@ -80,8 +80,8 @@ void ListenHandler::create_worker_thread(size_t num) ...@@ -80,8 +80,8 @@ void ListenHandler::create_worker_thread(size_t num)
} }
continue; continue;
} }
bufferevent *bev = bufferevent_socket_new(evbase_, info->sv[0], auto bev = bufferevent_socket_new(evbase_, info->sv[0],
BEV_OPT_DEFER_CALLBACKS); BEV_OPT_DEFER_CALLBACKS);
info->bev = bev; info->bev = bev;
if(LOG_ENABLED(INFO)) { if(LOG_ENABLED(INFO)) {
LLOG(INFO, this) << "Created thread #" << num_worker_; LLOG(INFO, this) << "Created thread #" << num_worker_;
...@@ -97,8 +97,8 @@ int ListenHandler::accept_connection(evutil_socket_t fd, ...@@ -97,8 +97,8 @@ int ListenHandler::accept_connection(evutil_socket_t fd,
LLOG(INFO, this) << "Accepted connection. fd=" << fd; LLOG(INFO, this) << "Accepted connection. fd=" << fd;
} }
if(num_worker_ == 0) { if(num_worker_ == 0) {
ClientHandler* client = ssl::accept_connection(evbase_, sv_ssl_ctx_, auto client = ssl::accept_connection(evbase_, sv_ssl_ctx_,
fd, addr, addrlen); fd, addr, addrlen);
client->set_spdy_session(spdy_); client->set_spdy_session(spdy_);
} else { } else {
size_t idx = worker_round_robin_cnt_ % num_worker_; size_t idx = worker_round_robin_cnt_ % num_worker_;
...@@ -108,7 +108,7 @@ int ListenHandler::accept_connection(evutil_socket_t fd, ...@@ -108,7 +108,7 @@ int ListenHandler::accept_connection(evutil_socket_t fd,
wev.client_fd = fd; wev.client_fd = fd;
memcpy(&wev.client_addr, addr, addrlen); memcpy(&wev.client_addr, addr, addrlen);
wev.client_addrlen = addrlen; wev.client_addrlen = addrlen;
evbuffer *output = bufferevent_get_output(workers_[idx].bev); auto output = bufferevent_get_output(workers_[idx].bev);
if(evbuffer_add(output, &wev, sizeof(wev)) != 0) { if(evbuffer_add(output, &wev, sizeof(wev)) != 0) {
LLOG(FATAL, this) << "evbuffer_add() failed"; LLOG(FATAL, this) << "evbuffer_add() failed";
return -1; return -1;
......
...@@ -52,7 +52,7 @@ Worker::~Worker() ...@@ -52,7 +52,7 @@ Worker::~Worker()
namespace { namespace {
void readcb(bufferevent *bev, void *arg) void readcb(bufferevent *bev, void *arg)
{ {
ThreadEventReceiver *receiver = reinterpret_cast<ThreadEventReceiver*>(arg); auto receiver = reinterpret_cast<ThreadEventReceiver*>(arg);
receiver->on_read(bev); receiver->on_read(bev);
} }
} // namespace } // namespace
...@@ -71,17 +71,16 @@ void eventcb(bufferevent *bev, short events, void *arg) ...@@ -71,17 +71,16 @@ void eventcb(bufferevent *bev, short events, void *arg)
void Worker::run() void Worker::run()
{ {
event_base *evbase = event_base_new(); auto evbase = event_base_new();
bufferevent *bev = bufferevent_socket_new(evbase, fd_, auto bev = bufferevent_socket_new(evbase, fd_, BEV_OPT_DEFER_CALLBACKS);
BEV_OPT_DEFER_CALLBACKS); SpdySession *spdy = nullptr;
SpdySession *spdy = 0;
if(get_config()->downstream_proto == PROTO_SPDY) { if(get_config()->downstream_proto == PROTO_SPDY) {
spdy = new SpdySession(evbase, cl_ssl_ctx_); spdy = new SpdySession(evbase, cl_ssl_ctx_);
if(spdy->init_notification() == -1) { if(spdy->init_notification() == -1) {
DIE(); DIE();
} }
} }
ThreadEventReceiver *receiver = new ThreadEventReceiver(sv_ssl_ctx_, spdy); auto receiver = new ThreadEventReceiver(sv_ssl_ctx_, spdy);
bufferevent_enable(bev, EV_READ); bufferevent_enable(bev, EV_READ);
bufferevent_setcb(bev, readcb, 0, eventcb, receiver); bufferevent_setcb(bev, readcb, 0, eventcb, receiver);
......
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