Commit f0fc0267 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

shrpx: Check return value of library functions

parent 9f28b305
......@@ -681,9 +681,15 @@ int HttpsUpstream::on_downstream_body(Downstream *downstream,
return -1;
}
}
evbuffer_add(output, data, len);
if(evbuffer_add(output, data, len) != 0) {
ULOG(FATAL, this) << "evbuffer_add() failed";
return -1;
}
if(downstream->get_chunked_response()) {
evbuffer_add(output, "\r\n", 2);
if(evbuffer_add(output, "\r\n", 2) != 0) {
ULOG(FATAL, this) << "evbuffer_add() failed";
return -1;
}
}
return 0;
}
......
......@@ -109,7 +109,10 @@ int ListenHandler::accept_connection(evutil_socket_t fd,
memcpy(&wev.client_addr, addr, addrlen);
wev.client_addrlen = addrlen;
evbuffer *output = bufferevent_get_output(workers_[idx].bev);
evbuffer_add(output, &wev, sizeof(wev));
if(evbuffer_add(output, &wev, sizeof(wev)) != 0) {
LLOG(FATAL, this) << "evbuffer_add() failed";
return -1;
}
}
return 0;
}
......
......@@ -228,8 +228,11 @@ void eventcb(bufferevent *bev, short events, void *ptr)
}
int fd = bufferevent_getfd(bev);
int val = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<char *>(&val), sizeof(val));
if(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<char *>(&val), sizeof(val)) == -1) {
SSLOG(WARNING, spdy) << "Setting option TCP_NODELAY failed: "
<< strerror(errno);
}
} else if(events & BEV_EVENT_EOF) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, spdy) << "EOF";
......
......@@ -508,8 +508,11 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr)
}
int fd = bufferevent_getfd(bev);
int val = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<char *>(&val), sizeof(val));
if(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<char *>(&val), sizeof(val)) == -1) {
DCLOG(WARNING, dconn) << "Setting option TCP_NODELAY failed: "
<< strerror(errno);
}
} else if(events & BEV_EVENT_EOF) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "EOF. stream_id=" << downstream->get_stream_id();
......
......@@ -46,7 +46,12 @@ void ThreadEventReceiver::on_read(bufferevent *bev)
evbuffer *input = bufferevent_get_input(bev);
while(evbuffer_get_length(input) >= sizeof(WorkerEvent)) {
WorkerEvent wev;
evbuffer_remove(input, &wev, sizeof(WorkerEvent));
int nread = evbuffer_remove(input, &wev, sizeof(wev));
if(nread != sizeof(wev)) {
TLOG(FATAL, this) << "evbuffer_remove() removed fewer bytes. Expected:"
<< sizeof(wev) << " Actual:" << nread;
continue;
}
if(LOG_ENABLED(INFO)) {
TLOG(INFO, this) << "WorkerEvent: client_fd=" << wev.client_fd
<< ", addrlen=" << wev.client_addrlen;
......
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