|
|
@ -526,15 +526,14 @@ namespace util |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_Stream.reset (); |
|
|
|
m_Stream.reset (); |
|
|
|
m_Stream = nullptr; |
|
|
|
m_Stream = nullptr; |
|
|
|
// delete this
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HTTPConnection::Receive () |
|
|
|
void HTTPConnection::Receive () |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_Socket->async_read_some (boost::asio::buffer (m_Buffer, HTTP_CONNECTION_BUFFER_SIZE), |
|
|
|
m_Socket->async_read_some (boost::asio::buffer (m_Buffer, HTTP_CONNECTION_BUFFER_SIZE), |
|
|
|
boost::bind(&HTTPConnection::HandleReceive, this, |
|
|
|
std::bind(&HTTPConnection::HandleReceive, shared_from_this (), |
|
|
|
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); |
|
|
|
std::placeholders::_1, std::placeholders::_2)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HTTPConnection::HandleReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred) |
|
|
|
void HTTPConnection::HandleReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred) |
|
|
@ -968,8 +967,8 @@ namespace util |
|
|
|
m_BufferLen = len; |
|
|
|
m_BufferLen = len; |
|
|
|
i2p::client::context.GetSharedLocalDestination ()->RequestDestination (destination); |
|
|
|
i2p::client::context.GetSharedLocalDestination ()->RequestDestination (destination); |
|
|
|
m_Timer.expires_from_now (boost::posix_time::seconds(HTTP_DESTINATION_REQUEST_TIMEOUT)); |
|
|
|
m_Timer.expires_from_now (boost::posix_time::seconds(HTTP_DESTINATION_REQUEST_TIMEOUT)); |
|
|
|
m_Timer.async_wait (boost::bind (&HTTPConnection::HandleDestinationRequestTimeout, |
|
|
|
m_Timer.async_wait (std::bind (&HTTPConnection::HandleDestinationRequestTimeout, |
|
|
|
this, boost::asio::placeholders::error, destination, port, m_Buffer, m_BufferLen)); |
|
|
|
shared_from_this (), std::placeholders::_1, destination, port, m_Buffer, m_BufferLen)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1002,8 +1001,8 @@ namespace util |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_Stream) |
|
|
|
if (m_Stream) |
|
|
|
m_Stream->AsyncReceive (boost::asio::buffer (m_StreamBuffer, 8192), |
|
|
|
m_Stream->AsyncReceive (boost::asio::buffer (m_StreamBuffer, 8192), |
|
|
|
boost::bind (&HTTPConnection::HandleStreamReceive, this, |
|
|
|
std::bind (&HTTPConnection::HandleStreamReceive, shared_from_this (), |
|
|
|
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred), |
|
|
|
std::placeholders::_1, std::placeholders::_2), |
|
|
|
45); // 45 seconds timeout
|
|
|
|
45); // 45 seconds timeout
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1012,7 +1011,7 @@ namespace util |
|
|
|
if (!ecode) |
|
|
|
if (!ecode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
boost::asio::async_write (*m_Socket, boost::asio::buffer (m_StreamBuffer, bytes_transferred), |
|
|
|
boost::asio::async_write (*m_Socket, boost::asio::buffer (m_StreamBuffer, bytes_transferred), |
|
|
|
boost::bind (&HTTPConnection::HandleWrite, this, boost::asio::placeholders::error)); |
|
|
|
std::bind (&HTTPConnection::HandleWrite, shared_from_this (), std::placeholders::_1)); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1033,8 +1032,7 @@ namespace util |
|
|
|
m_Reply.headers[1].value = "text/html"; |
|
|
|
m_Reply.headers[1].value = "text/html"; |
|
|
|
|
|
|
|
|
|
|
|
boost::asio::async_write (*m_Socket, m_Reply.to_buffers(status), |
|
|
|
boost::asio::async_write (*m_Socket, m_Reply.to_buffers(status), |
|
|
|
boost::bind (&HTTPConnection::HandleWriteReply, this, |
|
|
|
std::bind (&HTTPConnection::HandleWriteReply, shared_from_this (), std::placeholders::_1)); |
|
|
|
boost::asio::placeholders::error)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
HTTPServer::HTTPServer (int port): |
|
|
|
HTTPServer::HTTPServer (int port): |
|
|
@ -1085,14 +1083,15 @@ namespace util |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!ecode) |
|
|
|
if (!ecode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CreateConnection(m_NewSocket); // new HTTPConnection(m_NewSocket);
|
|
|
|
CreateConnection(m_NewSocket); |
|
|
|
Accept (); |
|
|
|
Accept (); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HTTPServer::CreateConnection(boost::asio::ip::tcp::socket * m_NewSocket) |
|
|
|
void HTTPServer::CreateConnection(boost::asio::ip::tcp::socket * m_NewSocket) |
|
|
|
{ |
|
|
|
{ |
|
|
|
new HTTPConnection (m_NewSocket); |
|
|
|
auto conn = std::make_shared<HTTPConnection> (m_NewSocket); |
|
|
|
|
|
|
|
conn->Receive (); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|