mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-11 19:10:55 +00:00
* HTTPServer.{cpp,h}: drop rest of streaming support
This commit is contained in:
parent
4fa4ba6301
commit
2a1fe99a29
@ -17,8 +17,6 @@
|
||||
#include "NetDb.h"
|
||||
#include "HTTP.h"
|
||||
#include "LeaseSet.h"
|
||||
#include "I2PEndian.h"
|
||||
#include "Streaming.h"
|
||||
#include "Destination.h"
|
||||
#include "RouterContext.h"
|
||||
#include "ClientContext.h"
|
||||
@ -234,9 +232,6 @@ namespace http {
|
||||
|
||||
void HTTPConnection::Terminate ()
|
||||
{
|
||||
if (!m_Stream) return;
|
||||
m_Stream->Close ();
|
||||
m_Stream = nullptr;
|
||||
m_Socket->close ();
|
||||
}
|
||||
|
||||
@ -250,15 +245,10 @@ namespace http {
|
||||
void HTTPConnection::HandleReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred)
|
||||
{
|
||||
if (!ecode)
|
||||
{
|
||||
if (!m_Stream) // new request
|
||||
{
|
||||
m_Buffer[bytes_transferred] = '\0';
|
||||
m_BufferLen = bytes_transferred;
|
||||
RunRequest();
|
||||
}
|
||||
else // follow-on
|
||||
m_Stream->Send ((uint8_t *)m_Buffer, bytes_transferred);
|
||||
Receive ();
|
||||
}
|
||||
else if (ecode != boost::asio::error::operation_aborted)
|
||||
@ -289,17 +279,6 @@ namespace http {
|
||||
}
|
||||
}
|
||||
|
||||
void HTTPConnection::HandleWrite (const boost::system::error_code& ecode)
|
||||
{
|
||||
if (ecode || (m_Stream && !m_Stream->IsOpen ()))
|
||||
{
|
||||
if (ecode != boost::asio::error::operation_aborted)
|
||||
Terminate ();
|
||||
}
|
||||
else // data keeps coming
|
||||
AsyncStreamReceive ();
|
||||
}
|
||||
|
||||
void HTTPConnection::HandleRequest (const std::string &uri)
|
||||
{
|
||||
std::stringstream s;
|
||||
@ -769,31 +748,6 @@ namespace http {
|
||||
s << "Peer test is running" << std::endl;
|
||||
}
|
||||
|
||||
void HTTPConnection::AsyncStreamReceive ()
|
||||
{
|
||||
if (m_Stream)
|
||||
m_Stream->AsyncReceive (boost::asio::buffer (m_StreamBuffer, 8192),
|
||||
std::bind (&HTTPConnection::HandleStreamReceive, shared_from_this (),
|
||||
std::placeholders::_1, std::placeholders::_2),
|
||||
45); // 45 seconds timeout
|
||||
}
|
||||
|
||||
void HTTPConnection::HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred)
|
||||
{
|
||||
if (!ecode)
|
||||
{
|
||||
boost::asio::async_write (*m_Socket, boost::asio::buffer (m_StreamBuffer, bytes_transferred),
|
||||
std::bind (&HTTPConnection::HandleWrite, shared_from_this (), std::placeholders::_1));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ecode == boost::asio::error::timed_out)
|
||||
SendError ("Host not responding");
|
||||
else if (ecode != boost::asio::error::operation_aborted)
|
||||
Terminate ();
|
||||
}
|
||||
}
|
||||
|
||||
void HTTPConnection::SendReply (const std::string& content, int code)
|
||||
{
|
||||
std::time_t time_now = std::time(nullptr);
|
||||
|
@ -13,17 +13,15 @@ namespace http {
|
||||
|
||||
HTTPConnection (std::shared_ptr<boost::asio::ip::tcp::socket> socket):
|
||||
m_Socket (socket), m_Timer (socket->get_io_service ()),
|
||||
m_Stream (nullptr), m_BufferLen (0) {};
|
||||
m_BufferLen (0) {};
|
||||
void Receive ();
|
||||
|
||||
private:
|
||||
|
||||
void Terminate ();
|
||||
void HandleReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||
void AsyncStreamReceive ();
|
||||
void HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||
void HandleWriteReply(const boost::system::error_code& ecode);
|
||||
void HandleWrite (const boost::system::error_code& ecode);
|
||||
|
||||
void SendReply (const std::string& content, int code = 200);
|
||||
void SendError (const std::string& message);
|
||||
|
||||
@ -51,8 +49,7 @@ namespace http {
|
||||
|
||||
std::shared_ptr<boost::asio::ip::tcp::socket> m_Socket;
|
||||
boost::asio::deadline_timer m_Timer;
|
||||
std::shared_ptr<i2p::stream::Stream> m_Stream;
|
||||
char m_Buffer[HTTP_CONNECTION_BUFFER_SIZE + 1], m_StreamBuffer[HTTP_CONNECTION_BUFFER_SIZE + 1];
|
||||
char m_Buffer[HTTP_CONNECTION_BUFFER_SIZE + 1];
|
||||
size_t m_BufferLen;
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user