From 7f2b9ae75db7523a20b9792b5949ebff4a0f4366 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 15 Jul 2012 21:15:28 +0900 Subject: [PATCH] Ensure that upstream->send() is called in callback. Log error string in case of network error --- examples/shrpx_client_handler.cc | 5 ++++- examples/shrpx_spdy_upstream.cc | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/examples/shrpx_client_handler.cc b/examples/shrpx_client_handler.cc index 3b9613e1..0f3519d1 100644 --- a/examples/shrpx_client_handler.cc +++ b/examples/shrpx_client_handler.cc @@ -24,6 +24,8 @@ */ #include "shrpx_client_handler.h" +#include + #include "shrpx_upstream.h" #include "shrpx_spdy_upstream.h" #include "shrpx_https_upstream.h" @@ -73,7 +75,8 @@ void upstream_eventcb(bufferevent *bev, short events, void *arg) } if(events & BEV_EVENT_ERROR) { if(ENABLE_LOG) { - LOG(INFO) << "Upstream network error"; + LOG(INFO) << "Upstream network error: " + << evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()); } finish = true; } diff --git a/examples/shrpx_spdy_upstream.cc b/examples/shrpx_spdy_upstream.cc index 489679a6..effdc824 100644 --- a/examples/shrpx_spdy_upstream.cc +++ b/examples/shrpx_spdy_upstream.cc @@ -25,6 +25,7 @@ #include "shrpx_spdy_upstream.h" #include +#include #include #include "shrpx_client_handler.h" @@ -441,7 +442,6 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr) } else { upstream->on_downstream_body_complete(downstream); } - upstream->send(); } else if(downstream->get_response_state() == Downstream::MSG_COMPLETE) { // For SSL tunneling? upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); @@ -450,13 +450,21 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr) // on_stream_close_callback delete downstream. upstream->error_reply(downstream, 502); downstream->set_response_state(Downstream::MSG_COMPLETE); - upstream->send(); - // At this point, downstream may be deleted. } + upstream->send(); + // At this point, downstream may be deleted. } } else if(events & (BEV_EVENT_ERROR | BEV_EVENT_TIMEOUT)) { if(ENABLE_LOG) { - LOG(INFO) << "Downstream error/timeout. Downstream " << downstream; + if(events & BEV_EVENT_ERROR) { + LOG(INFO) << "Downstream network error: " + << evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()); + } else { + LOG(INFO) << "Downstream timeout"; + } + if(downstream->tunnel_established()) { + LOG(INFO) << "Note: this is tunnel connection"; + } } if(downstream->get_request_state() == Downstream::STREAM_CLOSED) { upstream->remove_downstream(downstream); @@ -483,9 +491,9 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr) upstream->error_reply(downstream, status); } downstream->set_response_state(Downstream::MSG_COMPLETE); - upstream->send(); - // At this point, downstream may be deleted. } + upstream->send(); + // At this point, downstream may be deleted. } } }