@@ -43,30 +43,29 @@ ProxyReply::ProxyReply(Request& request,
4343
4444ProxyReply ::~ProxyReply ()
4545{
46- if (sessionProcess_ && sessionProcess_ -> sessionId ().empty ()) {
46+ if (sessionProcess_ && sessionProcess_ -> sessionId ().empty ())
4747 sessionProcess_ -> stop ();
48- }
49-
50- boost ::system ::error_code ignored_ec ;
51- if (socket_ .get ()) {
52- socket_ -> shutdown (boost ::asio ::ip ::tcp ::socket ::shutdown_both , ignored_ec );
53- socket_ -> close ();
54- }
5548
49+ closeClientSocket ();
50+ }
51+
52+ void ProxyReply ::closeClientSocket ()
53+ {
54+ if (socket_ .get ()) {
55+ boost ::system ::error_code ignored_ec ;
56+ socket_ -> shutdown (boost ::asio ::ip ::tcp ::socket ::shutdown_both , ignored_ec );
57+ socket_ -> close ();
58+ socket_ .reset ();
59+ }
5660}
5761
5862void ProxyReply ::reset (const Wt ::EntryPoint * ep )
5963{
60- if (sessionProcess_ && sessionProcess_ -> sessionId ().empty ()) {
64+ if (sessionProcess_ && sessionProcess_ -> sessionId ().empty ())
6165 sessionProcess_ -> stop ();
62- }
6366 sessionProcess_ .reset ();
64- boost ::system ::error_code ignored_ec ;
65- if (socket_ .get ()) {
66- socket_ -> shutdown (boost ::asio ::ip ::tcp ::socket ::shutdown_both , ignored_ec );
67- socket_ -> close ();
68- }
69- socket_ .reset ();
67+
68+ closeClientSocket ();
7069 contentType_ .clear ();
7170 requestBuf_ .consume (requestBuf_ .size ());
7271 responseBuf_ .consume (responseBuf_ .size ());
@@ -118,8 +117,10 @@ bool ProxyReply::consumeData(Buffer::const_iterator begin,
118117
119118 if (sessionProcess_ ) {
120119 // Connection with child already established, send request data
121- asio ::async_write (* socket_ , asio ::buffer (beginRequestBuf_ , endRequestBuf_ - beginRequestBuf_ ),
122- boost ::bind (& ProxyReply ::handleDataWritten ,
120+ asio ::async_write
121+ (* socket_ ,
122+ asio ::buffer (beginRequestBuf_ , endRequestBuf_ - beginRequestBuf_ ),
123+ boost ::bind (& ProxyReply ::handleDataWritten ,
123124 boost ::dynamic_pointer_cast < ProxyReply > (shared_from_this ()),
124125 asio ::placeholders ::error ,
125126 asio ::placeholders ::bytes_transferred ));
@@ -150,7 +151,8 @@ bool ProxyReply::consumeData(Buffer::const_iterator begin,
150151 }
151152 }
152153
153- // Don't immediately consume more data, but do this when it has been sent to child
154+ // Don't immediately consume more data, but do this when it has
155+ // been sent to child
154156 return false;
155157}
156158
@@ -405,6 +407,8 @@ void ProxyReply::handleResponseRead(const boost::system::error_code &ec)
405407 || ec == boost ::asio ::error ::shut_down
406408 || ec == boost ::asio ::error ::operation_aborted
407409 || ec == boost ::asio ::error ::connection_reset ) {
410+ closeClientSocket ();
411+
408412 more_ = false;
409413
410414 if (request_ .type != Request ::TCP ) {
@@ -465,6 +469,8 @@ bool ProxyReply::nextContentBuffers(std::vector<asio::const_buffer>& result)
465469
466470void ProxyReply ::error (status_type status )
467471{
472+ closeClientSocket ();
473+
468474 if (request_ .type == Request ::HTTP ) {
469475 setStatus (status );
470476 setCloseConnection ();
@@ -490,6 +496,8 @@ bool ProxyReply::sendReload()
490496 "if (window.Wt) window.Wt._p_.quit(null); window.location.reload(true);" ;
491497 send ();
492498
499+ closeClientSocket ();
500+
493501 return true;
494502 }
495503
0 commit comments