diff --git a/examples/tiny-nghttpd.c b/examples/tiny-nghttpd.c index 79fc0c46..037155e3 100644 --- a/examples/tiny-nghttpd.c +++ b/examples/tiny-nghttpd.c @@ -422,7 +422,11 @@ static int server_init(server *serv, const char *node, const char *service) continue; } - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, optlen); + rv = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, optlen); + + if(rv == -1) { + print_errno("setsockopt", errno); + } if(bind(fd, rp->ai_addr, rp->ai_addrlen) != 0) { close(fd); @@ -552,7 +556,10 @@ static int handle_timer(io_loop *loop, uint32_t events, void *ptr) ssize_t nread; while((nread = read(tmr->fd, buf, sizeof(buf))) == -1 && errno == EINTR); - break; + + if(nread == -1) { + break; + } } update_date(); @@ -566,6 +573,7 @@ static int handle_accept(io_loop *loop, uint32_t events, void *ptr) server *serv = ptr; int on = 1; socklen_t optlen = sizeof(on); + int rv; for(;;) { connection *conn; @@ -574,7 +582,7 @@ static int handle_accept(io_loop *loop, uint32_t events, void *ptr) errno == EINTR); if(acfd == -1) { - switch(acfd) { + switch(errno) { case ENETDOWN: case EPROTO: case ENOPROTOOPT: @@ -588,7 +596,11 @@ static int handle_accept(io_loop *loop, uint32_t events, void *ptr) return 0; } - setsockopt(acfd, IPPROTO_TCP, TCP_NODELAY, &on, optlen); + rv = setsockopt(acfd, IPPROTO_TCP, TCP_NODELAY, &on, optlen); + + if(rv == -1) { + print_errno("setsockopt", errno); + } conn = connection_new(acfd); diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 25ff748b..7bfc24d3 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -122,6 +122,11 @@ Config::Config() nghttp2_option_set_recv_client_preface(session_option, 1); } +Config::~Config() +{ + nghttp2_option_del(session_option); +} + Stream::Stream(Http2Handler *handler, int32_t stream_id) : handler(handler), rtimer(nullptr), @@ -512,7 +517,9 @@ int Http2Handler::on_read() return -1; } - evbuffer_drain(input, len); + if(evbuffer_drain(input, len) == -1) { + std::cerr << "evbuffer_drain() failed" << std::endl; + } } return send(); @@ -1268,7 +1275,9 @@ void worker_readcb(bufferevent *bev, void *arg) auto input = bufferevent_get_input(bev); while(evbuffer_get_length(input) >= sizeof(ClientInfo)) { ClientInfo client; - evbuffer_remove(input, &client, sizeof(client)); + if(evbuffer_remove(input, &client, sizeof(client)) == -1) { + std::cerr << "evbuffer_remove() failed" << std::endl; + } sessions->accept_connection(client.fd); } } diff --git a/src/HttpServer.h b/src/HttpServer.h index 2b05f446..6c856113 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -80,6 +80,7 @@ struct Config { bool error_gzip; bool early_response; Config(); + ~Config(); }; class Http2Handler;