nghttpx: Handle socket creation error

This commit is contained in:
Tatsuhiro Tsujikawa 2014-08-19 21:22:53 +09:00
parent a5dfe24e49
commit 345121975a
2 changed files with 18 additions and 1 deletions

View File

@ -401,9 +401,18 @@ int Http2Session::initiate_connection()
<< ":" << ":"
<< get_config()->downstream_http_proxy_port; << get_config()->downstream_http_proxy_port;
} }
bev_ = bufferevent_socket_new(evbase_, -1, BEV_OPT_DEFER_CALLBACKS);
auto fd = socket(get_config()->downstream_http_proxy_addr.storage.ss_family,
SOCK_STREAM | SOCK_CLOEXEC, 0);
if(fd == -1) {
return SHRPX_ERR_NETWORK;
}
bev_ = bufferevent_socket_new(evbase_, fd, BEV_OPT_DEFER_CALLBACKS);
if(!bev_) { if(!bev_) {
SSLOG(ERROR, this) << "bufferevent_socket_new() failed"; SSLOG(ERROR, this) << "bufferevent_socket_new() failed";
close(fd);
return SHRPX_ERR_NETWORK; return SHRPX_ERR_NETWORK;
} }
bufferevent_enable(bev_, EV_READ); bufferevent_enable(bev_, EV_READ);
@ -488,6 +497,10 @@ int Http2Session::initiate_connection()
fd_ = socket(get_config()->downstream_addr.storage.ss_family, fd_ = socket(get_config()->downstream_addr.storage.ss_family,
SOCK_STREAM | SOCK_CLOEXEC, 0); SOCK_STREAM | SOCK_CLOEXEC, 0);
if(fd_ == -1) {
return SHRPX_ERR_NETWORK;
}
} }
bev_ = bufferevent_socket_new(evbase_, fd_, BEV_OPT_DEFER_CALLBACKS); bev_ = bufferevent_socket_new(evbase_, fd_, BEV_OPT_DEFER_CALLBACKS);

View File

@ -81,6 +81,10 @@ int HttpDownstreamConnection::attach_downstream(Downstream *downstream)
auto fd = socket(get_config()->downstream_addr.storage.ss_family, auto fd = socket(get_config()->downstream_addr.storage.ss_family,
SOCK_STREAM | SOCK_CLOEXEC, 0); SOCK_STREAM | SOCK_CLOEXEC, 0);
if(fd == -1) {
return SHRPX_ERR_NETWORK;
}
bev_ = bufferevent_socket_new bev_ = bufferevent_socket_new
(evbase, fd, (evbase, fd,
BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS); BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);