* HTTPServer.{cpp,h}: drop rest of streaming support

This commit is contained in:
hagen 2016-04-27 00:00:00 +00:00
parent 4fa4ba6301
commit 2a1fe99a29
2 changed files with 6 additions and 55 deletions

View File

@ -17,8 +17,6 @@
#include "NetDb.h" #include "NetDb.h"
#include "HTTP.h" #include "HTTP.h"
#include "LeaseSet.h" #include "LeaseSet.h"
#include "I2PEndian.h"
#include "Streaming.h"
#include "Destination.h" #include "Destination.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "ClientContext.h" #include "ClientContext.h"
@ -234,9 +232,6 @@ namespace http {
void HTTPConnection::Terminate () void HTTPConnection::Terminate ()
{ {
if (!m_Stream) return;
m_Stream->Close ();
m_Stream = nullptr;
m_Socket->close (); m_Socket->close ();
} }
@ -251,14 +246,9 @@ namespace http {
{ {
if (!ecode) if (!ecode)
{ {
if (!m_Stream) // new request m_Buffer[bytes_transferred] = '\0';
{ m_BufferLen = bytes_transferred;
m_Buffer[bytes_transferred] = '\0'; RunRequest();
m_BufferLen = bytes_transferred;
RunRequest();
}
else // follow-on
m_Stream->Send ((uint8_t *)m_Buffer, bytes_transferred);
Receive (); Receive ();
} }
else if (ecode != boost::asio::error::operation_aborted) 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) void HTTPConnection::HandleRequest (const std::string &uri)
{ {
std::stringstream s; std::stringstream s;
@ -769,31 +748,6 @@ namespace http {
s << "Peer test is running" << std::endl; 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) void HTTPConnection::SendReply (const std::string& content, int code)
{ {
std::time_t time_now = std::time(nullptr); std::time_t time_now = std::time(nullptr);

View File

@ -13,17 +13,15 @@ namespace http {
HTTPConnection (std::shared_ptr<boost::asio::ip::tcp::socket> socket): HTTPConnection (std::shared_ptr<boost::asio::ip::tcp::socket> socket):
m_Socket (socket), m_Timer (socket->get_io_service ()), m_Socket (socket), m_Timer (socket->get_io_service ()),
m_Stream (nullptr), m_BufferLen (0) {}; m_BufferLen (0) {};
void Receive (); void Receive ();
private: private:
void Terminate (); 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 AsyncStreamReceive ();
void HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void HandleWriteReply(const boost::system::error_code& ecode); 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 SendReply (const std::string& content, int code = 200);
void SendError (const std::string& message); void SendError (const std::string& message);
@ -51,8 +49,7 @@ namespace http {
std::shared_ptr<boost::asio::ip::tcp::socket> m_Socket; std::shared_ptr<boost::asio::ip::tcp::socket> m_Socket;
boost::asio::deadline_timer m_Timer; boost::asio::deadline_timer m_Timer;
std::shared_ptr<i2p::stream::Stream> m_Stream; char m_Buffer[HTTP_CONNECTION_BUFFER_SIZE + 1];
char m_Buffer[HTTP_CONNECTION_BUFFER_SIZE + 1], m_StreamBuffer[HTTP_CONNECTION_BUFFER_SIZE + 1];
size_t m_BufferLen; size_t m_BufferLen;
protected: protected: