nghttpx: Use nghttp2_session_mem_recv instead of nghttp2_session_recv
This commit is contained in:
parent
50dd7ada50
commit
0872ce27f4
|
@ -711,24 +711,6 @@ ssize_t send_callback(nghttp2_session *session,
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
|
||||||
ssize_t recv_callback(nghttp2_session *session,
|
|
||||||
uint8_t *data, size_t len, int flags, void *user_data)
|
|
||||||
{
|
|
||||||
auto http2session = reinterpret_cast<Http2Session*>(user_data);
|
|
||||||
auto bev = http2session->get_bev();
|
|
||||||
auto input = bufferevent_get_input(bev);
|
|
||||||
int nread = evbuffer_remove(input, data, len);
|
|
||||||
if(nread == -1) {
|
|
||||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
||||||
} else if(nread == 0) {
|
|
||||||
return NGHTTP2_ERR_WOULDBLOCK;
|
|
||||||
} else {
|
|
||||||
return nread;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int on_stream_close_callback
|
int on_stream_close_callback
|
||||||
(nghttp2_session *session, int32_t stream_id, nghttp2_error_code error_code,
|
(nghttp2_session *session, int32_t stream_id, nghttp2_error_code error_code,
|
||||||
|
@ -1215,7 +1197,6 @@ int Http2Session::on_connect()
|
||||||
nghttp2_session_callbacks callbacks;
|
nghttp2_session_callbacks callbacks;
|
||||||
memset(&callbacks, 0, sizeof(callbacks));
|
memset(&callbacks, 0, sizeof(callbacks));
|
||||||
callbacks.send_callback = send_callback;
|
callbacks.send_callback = send_callback;
|
||||||
callbacks.recv_callback = recv_callback;
|
|
||||||
callbacks.on_stream_close_callback = on_stream_close_callback;
|
callbacks.on_stream_close_callback = on_stream_close_callback;
|
||||||
callbacks.on_frame_recv_callback = on_frame_recv_callback;
|
callbacks.on_frame_recv_callback = on_frame_recv_callback;
|
||||||
callbacks.on_data_chunk_recv_callback = on_data_chunk_recv_callback;
|
callbacks.on_data_chunk_recv_callback = on_data_chunk_recv_callback;
|
||||||
|
@ -1290,27 +1271,33 @@ int Http2Session::on_connect()
|
||||||
|
|
||||||
int Http2Session::on_read()
|
int Http2Session::on_read()
|
||||||
{
|
{
|
||||||
int rv = 0;
|
ssize_t rv = 0;
|
||||||
if((rv = nghttp2_session_recv(session_)) < 0) {
|
auto input = bufferevent_get_input(bev_);
|
||||||
if(rv != NGHTTP2_ERR_EOF) {
|
auto inputlen = evbuffer_get_length(input);
|
||||||
SSLOG(ERROR, this) << "nghttp2_session_recv() returned error: "
|
auto mem = evbuffer_pullup(input, -1);
|
||||||
<< nghttp2_strerror(rv);
|
|
||||||
}
|
rv = nghttp2_session_mem_recv(session_, mem, inputlen);
|
||||||
} else if((rv = nghttp2_session_send(session_)) < 0) {
|
if(rv < 0) {
|
||||||
|
SSLOG(ERROR, this) << "nghttp2_session_recv() returned error: "
|
||||||
|
<< nghttp2_strerror(rv);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
evbuffer_drain(input, rv);
|
||||||
|
rv = nghttp2_session_send(session_);
|
||||||
|
if(rv < 0) {
|
||||||
SSLOG(ERROR, this) << "nghttp2_session_send() returned error: "
|
SSLOG(ERROR, this) << "nghttp2_session_send() returned error: "
|
||||||
<< nghttp2_strerror(rv);
|
<< nghttp2_strerror(rv);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if(rv == 0) {
|
if(nghttp2_session_want_read(session_) == 0 &&
|
||||||
if(nghttp2_session_want_read(session_) == 0 &&
|
nghttp2_session_want_write(session_) == 0 &&
|
||||||
nghttp2_session_want_write(session_) == 0 &&
|
evbuffer_get_length(bufferevent_get_output(bev_)) == 0) {
|
||||||
evbuffer_get_length(bufferevent_get_output(bev_)) == 0) {
|
if(LOG_ENABLED(INFO)) {
|
||||||
if(LOG_ENABLED(INFO)) {
|
SSLOG(INFO, this) << "No more read/write for this session";
|
||||||
SSLOG(INFO, this) << "No more read/write for this session";
|
|
||||||
}
|
|
||||||
rv = -1;
|
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return rv;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Http2Session::on_write()
|
int Http2Session::on_write()
|
||||||
|
|
|
@ -73,25 +73,6 @@ ssize_t send_callback(nghttp2_session *session,
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
|
||||||
ssize_t recv_callback(nghttp2_session *session,
|
|
||||||
uint8_t *data, size_t len, int flags, void *user_data)
|
|
||||||
{
|
|
||||||
auto upstream = reinterpret_cast<Http2Upstream*>(user_data);
|
|
||||||
auto handler = upstream->get_client_handler();
|
|
||||||
auto bev = handler->get_bev();
|
|
||||||
auto input = bufferevent_get_input(bev);
|
|
||||||
int nread = evbuffer_remove(input, data, len);
|
|
||||||
if(nread == -1) {
|
|
||||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
||||||
} else if(nread == 0) {
|
|
||||||
return NGHTTP2_ERR_WOULDBLOCK;
|
|
||||||
} else {
|
|
||||||
return nread;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int on_stream_close_callback
|
int on_stream_close_callback
|
||||||
(nghttp2_session *session, int32_t stream_id, nghttp2_error_code error_code,
|
(nghttp2_session *session, int32_t stream_id, nghttp2_error_code error_code,
|
||||||
|
@ -533,7 +514,6 @@ Http2Upstream::Http2Upstream(ClientHandler *handler)
|
||||||
nghttp2_session_callbacks callbacks;
|
nghttp2_session_callbacks callbacks;
|
||||||
memset(&callbacks, 0, sizeof(callbacks));
|
memset(&callbacks, 0, sizeof(callbacks));
|
||||||
callbacks.send_callback = send_callback;
|
callbacks.send_callback = send_callback;
|
||||||
callbacks.recv_callback = recv_callback;
|
|
||||||
callbacks.on_stream_close_callback = on_stream_close_callback;
|
callbacks.on_stream_close_callback = on_stream_close_callback;
|
||||||
callbacks.on_frame_recv_callback = on_frame_recv_callback;
|
callbacks.on_frame_recv_callback = on_frame_recv_callback;
|
||||||
callbacks.on_data_chunk_recv_callback = on_data_chunk_recv_callback;
|
callbacks.on_data_chunk_recv_callback = on_data_chunk_recv_callback;
|
||||||
|
@ -593,27 +573,34 @@ Http2Upstream::~Http2Upstream()
|
||||||
|
|
||||||
int Http2Upstream::on_read()
|
int Http2Upstream::on_read()
|
||||||
{
|
{
|
||||||
int rv = 0;
|
ssize_t rv = 0;
|
||||||
if((rv = nghttp2_session_recv(session_)) < 0) {
|
auto bev = handler_->get_bev();
|
||||||
if(rv != NGHTTP2_ERR_EOF) {
|
auto input = bufferevent_get_input(bev);
|
||||||
ULOG(ERROR, this) << "nghttp2_session_recv() returned error: "
|
auto inputlen = evbuffer_get_length(input);
|
||||||
<< nghttp2_strerror(rv);
|
auto mem = evbuffer_pullup(input, -1);
|
||||||
}
|
|
||||||
} else if((rv = nghttp2_session_send(session_)) < 0) {
|
rv = nghttp2_session_mem_recv(session_, mem, inputlen);
|
||||||
|
if(rv < 0) {
|
||||||
|
ULOG(ERROR, this) << "nghttp2_session_recv() returned error: "
|
||||||
|
<< nghttp2_strerror(rv);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
evbuffer_drain(input, rv);
|
||||||
|
rv = nghttp2_session_send(session_);
|
||||||
|
if(rv < 0) {
|
||||||
ULOG(ERROR, this) << "nghttp2_session_send() returned error: "
|
ULOG(ERROR, this) << "nghttp2_session_send() returned error: "
|
||||||
<< nghttp2_strerror(rv);
|
<< nghttp2_strerror(rv);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if(rv == 0) {
|
if(nghttp2_session_want_read(session_) == 0 &&
|
||||||
if(nghttp2_session_want_read(session_) == 0 &&
|
nghttp2_session_want_write(session_) == 0 &&
|
||||||
nghttp2_session_want_write(session_) == 0 &&
|
evbuffer_get_length(bufferevent_get_output(bev)) == 0) {
|
||||||
evbuffer_get_length(bufferevent_get_output(handler_->get_bev())) == 0) {
|
if(LOG_ENABLED(INFO)) {
|
||||||
if(LOG_ENABLED(INFO)) {
|
ULOG(INFO, this) << "No more read/write for this HTTP2 session";
|
||||||
ULOG(INFO, this) << "No more read/write for this HTTP2 session";
|
|
||||||
}
|
|
||||||
rv = -1;
|
|
||||||
}
|
}
|
||||||
|
rv = -1;
|
||||||
}
|
}
|
||||||
return rv;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Http2Upstream::on_write()
|
int Http2Upstream::on_write()
|
||||||
|
|
Loading…
Reference in New Issue