nghttpx: Use SOCK_NONBLOCK and SOCK_CLOEXEC flag in socketpair to avoid race
This commit is contained in:
parent
ca680c16e3
commit
21cbf417c8
|
@ -193,15 +193,13 @@ int Http2Session::init_notification()
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
int sockpair[2];
|
int sockpair[2];
|
||||||
rv = socketpair(AF_UNIX, SOCK_STREAM, 0, sockpair);
|
rv = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0,
|
||||||
|
sockpair);
|
||||||
if(rv == -1) {
|
if(rv == -1) {
|
||||||
SSLOG(FATAL, this) << "socketpair() failed: errno=" << errno;
|
SSLOG(FATAL, this) << "socketpair() failed: errno=" << errno;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for(int i = 0; i < 2; ++i) {
|
|
||||||
evutil_make_socket_nonblocking(sockpair[i]);
|
|
||||||
evutil_make_socket_closeonexec(sockpair[i]);
|
|
||||||
}
|
|
||||||
wrbev_ = bufferevent_socket_new(evbase_, sockpair[0],
|
wrbev_ = bufferevent_socket_new(evbase_, sockpair[0],
|
||||||
BEV_OPT_CLOSE_ON_FREE|
|
BEV_OPT_CLOSE_ON_FREE|
|
||||||
BEV_OPT_DEFER_CALLBACKS);
|
BEV_OPT_DEFER_CALLBACKS);
|
||||||
|
|
|
@ -103,17 +103,13 @@ void ListenHandler::create_worker_thread(size_t num)
|
||||||
for(size_t i = 0; i < num; ++i) {
|
for(size_t i = 0; i < num; ++i) {
|
||||||
int rv;
|
int rv;
|
||||||
auto info = util::make_unique<WorkerInfo>();
|
auto info = util::make_unique<WorkerInfo>();
|
||||||
rv = socketpair(AF_UNIX, SOCK_STREAM, 0, info->sv);
|
rv = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0,
|
||||||
|
info->sv);
|
||||||
if(rv == -1) {
|
if(rv == -1) {
|
||||||
LLOG(ERROR, this) << "socketpair() failed: errno=" << errno;
|
LLOG(ERROR, this) << "socketpair() failed: errno=" << errno;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int j = 0; j < 2; ++j) {
|
|
||||||
evutil_make_socket_nonblocking(info->sv[j]);
|
|
||||||
evutil_make_socket_closeonexec(info->sv[j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
info->sv_ssl_ctx = sv_ssl_ctx_;
|
info->sv_ssl_ctx = sv_ssl_ctx_;
|
||||||
info->cl_ssl_ctx = cl_ssl_ctx_;
|
info->cl_ssl_ctx = cl_ssl_ctx_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue