From a20ad03f7b7a67a879f2d4d42b52f8fd5102cab5 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 24 Dec 2014 00:46:04 +0900 Subject: [PATCH] nghttpd: Use evbuffer_pullup(input, -1) cause buffer is most likely just one --- src/HttpServer.cc | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index b505a7c8..1e688ce3 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -440,26 +440,21 @@ int Http2Handler::on_read() { int rv; auto input = bufferevent_get_input(bev_); + auto len = evbuffer_get_length(input); + if (len == 0) { + return 0; + } + auto data = evbuffer_pullup(input, -1); - for (;;) { - auto len = evbuffer_get_contiguous_space(input); + rv = nghttp2_session_mem_recv(session_, data, len); + if (rv < 0) { + std::cerr << "nghttp2_session_mem_recv() returned error: " + << nghttp2_strerror(rv) << std::endl; + return -1; + } - if (len == 0) { - break; - } - - auto data = evbuffer_pullup(input, len); - - rv = nghttp2_session_mem_recv(session_, data, len); - if (rv < 0) { - std::cerr << "nghttp2_session_mem_recv() returned error: " - << nghttp2_strerror(rv) << std::endl; - return -1; - } - - if (evbuffer_drain(input, len) == -1) { - std::cerr << "evbuffer_drain() failed" << std::endl; - } + if (evbuffer_drain(input, len) == -1) { + std::cerr << "evbuffer_drain() failed" << std::endl; } return send();