From 78523c6701cd2af61ee3f22cb0a1423afbf312f5 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 22 Feb 2013 19:26:41 +0900 Subject: [PATCH] shrpx: Fix backend SPDY connection does not go through proxy --- src/shrpx_spdy_session.cc | 14 +++++++++++--- src/shrpx_spdy_session.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/shrpx_spdy_session.cc b/src/shrpx_spdy_session.cc index ae21563..ce9b8d2 100644 --- a/src/shrpx_spdy_session.cc +++ b/src/shrpx_spdy_session.cc @@ -78,6 +78,12 @@ int SpdySession::disconnect() SSL_shutdown(ssl_); } if(bev_) { + int fd = bufferevent_getfd(bev_); + if(fd != -1 && fd_ == -1) { + fd_ = fd; + } else if(fd != -1 && fd_ != -1) { + assert(fd == fd_); + } bufferevent_disable(bev_, EV_READ | EV_WRITE); bufferevent_free(bev_); bev_ = 0; @@ -273,8 +279,8 @@ void proxy_readcb(bufferevent *bev, void *ptr) switch(spdy->get_state()) { case SpdySession::PROXY_CONNECTED: // The current bufferevent is no longer necessary, so delete it - // here. - spdy->free_bev(); + // here. But we keep fd_ inside it. + spdy->unwrap_free_bev(); // Initiate SSL/TLS handshake through established tunnel. spdy->initiate_connection(); break; @@ -420,8 +426,10 @@ int SpdySession::initiate_connection() return 0; } -void SpdySession::free_bev() +void SpdySession::unwrap_free_bev() { + assert(fd_ == -1); + fd_ = bufferevent_getfd(bev_); bufferevent_free(bev_); bev_ = 0; } diff --git a/src/shrpx_spdy_session.h b/src/shrpx_spdy_session.h index 9069fbb..8c7c24c 100644 --- a/src/shrpx_spdy_session.h +++ b/src/shrpx_spdy_session.h @@ -90,7 +90,7 @@ public: void notify(); bufferevent* get_bev() const; - void free_bev(); + void unwrap_free_bev(); int get_state() const; void set_state(int state);