mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-31 04:44:13 +00:00
* HTTPServer.{cpp,h}: merge HandleWriteReply & Terminate : the same purpose
This commit is contained in:
parent
fd928e8d12
commit
0c8fdfca7d
@ -230,11 +230,6 @@ namespace http {
|
|||||||
{ "stats.i2p", "http://7tbay5p4kzeekxvyvbf6v7eauazemsnnl2aoyqhg5jzpr5eke7tq.b32.i2p/cgi-bin/jump.cgi?a=" },
|
{ "stats.i2p", "http://7tbay5p4kzeekxvyvbf6v7eauazemsnnl2aoyqhg5jzpr5eke7tq.b32.i2p/cgi-bin/jump.cgi?a=" },
|
||||||
};
|
};
|
||||||
|
|
||||||
void HTTPConnection::Terminate ()
|
|
||||||
{
|
|
||||||
m_Socket->close ();
|
|
||||||
}
|
|
||||||
|
|
||||||
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),
|
||||||
@ -244,16 +239,16 @@ namespace http {
|
|||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
if (!ecode)
|
if (ecode) {
|
||||||
{
|
if (ecode != boost::asio::error::operation_aborted)
|
||||||
|
Terminate (ecode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_Buffer[bytes_transferred] = '\0';
|
m_Buffer[bytes_transferred] = '\0';
|
||||||
m_BufferLen = bytes_transferred;
|
m_BufferLen = bytes_transferred;
|
||||||
RunRequest();
|
RunRequest();
|
||||||
Receive ();
|
Receive ();
|
||||||
}
|
}
|
||||||
else if (ecode != boost::asio::error::operation_aborted)
|
|
||||||
Terminate ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HTTPConnection::RunRequest ()
|
void HTTPConnection::RunRequest ()
|
||||||
{
|
{
|
||||||
@ -269,14 +264,13 @@ namespace http {
|
|||||||
HandleRequest (request.uri);
|
HandleRequest (request.uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPConnection::HandleWriteReply (const boost::system::error_code& ecode)
|
void HTTPConnection::Terminate (const boost::system::error_code& ecode)
|
||||||
{
|
|
||||||
if (ecode != boost::asio::error::operation_aborted)
|
|
||||||
{
|
{
|
||||||
|
if (ecode == boost::asio::error::operation_aborted)
|
||||||
|
return;
|
||||||
boost::system::error_code ignored_ec;
|
boost::system::error_code ignored_ec;
|
||||||
m_Socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
|
m_Socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
|
||||||
Terminate ();
|
m_Socket->close ();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPConnection::HandleRequest (const std::string &uri)
|
void HTTPConnection::HandleRequest (const std::string &uri)
|
||||||
@ -767,7 +761,7 @@ namespace http {
|
|||||||
buffers.push_back(boost::asio::buffer(content));
|
buffers.push_back(boost::asio::buffer(content));
|
||||||
|
|
||||||
boost::asio::async_write (*m_Socket, buffers,
|
boost::asio::async_write (*m_Socket, buffers,
|
||||||
std::bind (&HTTPConnection::HandleWriteReply, shared_from_this (), std::placeholders::_1));
|
std::bind (&HTTPConnection::Terminate, shared_from_this (), std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPConnection::SendError(const std::string& content)
|
void HTTPConnection::SendError(const std::string& content)
|
||||||
|
@ -18,9 +18,8 @@ namespace http {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Terminate ();
|
|
||||||
void HandleReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
void HandleReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||||
void HandleWriteReply(const boost::system::error_code& ecode);
|
void Terminate (const boost::system::error_code& ecode);
|
||||||
|
|
||||||
void SendReply (const std::string& content, int code = 200);
|
void SendReply (const std::string& content, int code = 200);
|
||||||
void SendError (const std::string& message);
|
void SendError (const std::string& message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user