Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
Revert "Bugfix/http destruction (#1865)"
Browse files Browse the repository at this point in the history
This reverts commit 879623b.
  • Loading branch information
ejfitzgerald committed Nov 1, 2019
1 parent 879623b commit 2d7381d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 136 deletions.
53 changes: 15 additions & 38 deletions libs/http/include/http/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ class HTTPConnection : public AbstractHTTPConnection,
public std::enable_shared_from_this<HTTPConnection>
{
public:
using HTTPConnectionManagerPtr = std::weak_ptr<HTTPConnectionManager>;
using ResponseQueueType = std::deque<HTTPResponse>;
using ConnectionType = typename AbstractHTTPConnection::SharedType;
using HandleType = HTTPConnectionManager::HandleType;
using SharedRequestType = std::shared_ptr<HTTPRequest>;
using BufferPointerType = std::shared_ptr<asio::streambuf>;
using ResponseQueueType = std::deque<HTTPResponse>;
using ConnectionType = typename AbstractHTTPConnection::SharedType;
using HandleType = HTTPConnectionManager::HandleType;
using SharedRequestType = std::shared_ptr<HTTPRequest>;
using BufferPointerType = std::shared_ptr<asio::streambuf>;

static constexpr char const *LOGGING_NAME = "HTTPConnection";

HTTPConnection(asio::ip::tcp::tcp::socket socket, HTTPConnectionManagerPtr manager)
HTTPConnection(asio::ip::tcp::tcp::socket socket, HTTPConnectionManager &manager)
: socket_(std::move(socket))
, manager_(manager)
{
Expand All @@ -57,23 +56,13 @@ class HTTPConnection : public AbstractHTTPConnection,

~HTTPConnection() override
{
auto ptr = manager_.lock();
if (ptr)
{
ptr->Leave(handle_);
}
manager_.Leave(handle_);
}

void Start()
{
is_open_ = true;
auto ptr = manager_.lock();

if (ptr)
{
handle_ = ptr->Join(shared_from_this());
}

handle_ = manager_.Join(shared_from_this());
if (is_open_)
{
ReadHeader();
Expand Down Expand Up @@ -158,15 +147,11 @@ class HTTPConnection : public AbstractHTTPConnection,
request->SetOriginatingAddress(remote_endpoint.address().to_string(), remote_endpoint.port());

// push the request to the main server
auto ptr = manager_.lock();
if (ptr)
{
ptr->PushRequest(handle_, *request);
manager_.PushRequest(handle_, *request);

if (is_open_)
{
ReadHeader(buffer_ptr);
}
if (is_open_)
{
ReadHeader(buffer_ptr);
}
return;
}
Expand Down Expand Up @@ -230,11 +215,7 @@ class HTTPConnection : public AbstractHTTPConnection,
}
else
{
auto ptr = manager_.lock();
if (ptr)
{
ptr->Leave(handle_);
}
manager_.Leave(handle_);
}
};

Expand All @@ -244,16 +225,12 @@ class HTTPConnection : public AbstractHTTPConnection,
void Close()
{
is_open_ = false;
auto ptr = manager_.lock();
if (ptr)
{
ptr->Leave(handle_);
}
manager_.Leave(handle_);
}

private:
asio::ip::tcp::tcp::socket socket_;
HTTPConnectionManagerPtr manager_;
HTTPConnectionManager & manager_;
ResponseQueueType write_queue_;
Mutex write_mutex_;

Expand Down
3 changes: 1 addition & 2 deletions libs/http/include/http/http_connection_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace fetch {
namespace http {

class HTTPConnectionManager : public std::enable_shared_from_this<HTTPConnectionManager>
class HTTPConnectionManager
{
public:
using ConnectionType = typename AbstractHTTPConnection::SharedType;
Expand All @@ -36,7 +36,6 @@ class HTTPConnectionManager : public std::enable_shared_from_this<HTTPConnection
static constexpr char const *LOGGING_NAME = "HTTPConnectionManager";

explicit HTTPConnectionManager(AbstractHTTPServer &server);
~HTTPConnectionManager();

HandleType Join(ConnectionType client);
void Leave(HandleType handle);
Expand Down
6 changes: 1 addition & 5 deletions libs/http/include/http/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ class HTTPServer : public AbstractHTTPServer
auto socketWeak = socket_;
auto accepWeak = acceptor_;

manager_.reset();
socket_.reset();
acceptor_.reset();

networkManager_.Post([socketWeak, accepWeak] {
auto socket = socketWeak.lock();
auto acceptor = accepWeak.lock();
Expand Down Expand Up @@ -222,7 +218,7 @@ class HTTPServer : public AbstractHTTPServer
auto cb = [soc, accep, manager](std::error_code ec) {
if (!ec)
{
std::make_shared<HTTPConnection>(std::move(*soc), manager)->Start();
std::make_shared<HTTPConnection>(std::move(*soc), *manager)->Start();
}
else
{
Expand Down
5 changes: 0 additions & 5 deletions libs/http/src/http_connection_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ HTTPConnectionManager::HTTPConnectionManager(AbstractHTTPServer &server)
: server_(server)
{}

HTTPConnectionManager::~HTTPConnectionManager()
{
clients_.clear();
}

HTTPConnectionManager::HandleType HTTPConnectionManager::Join(ConnectionType client)
{
HandleType handle = AbstractHTTPServer::next_handle();
Expand Down
86 changes: 0 additions & 86 deletions libs/http/tests/unit/destruction_test.cpp

This file was deleted.

0 comments on commit 2d7381d

Please sign in to comment.