Skip to content
Snippets Groups Projects
Commit 3ac3a5cb authored by Konstantinos Sideris's avatar Konstantinos Sideris
Browse files

Remove unused code

parent ffecb194
No related branches found
No related tags found
No related merge requests found
......@@ -43,16 +43,6 @@ Client::on_resolve(std::shared_ptr<Session> s,
if (ec)
return s->on_failure(s->id, ec);
// Add new session to the list of active sessions so that we can access
// it if the user decides to cancel the corresponding request before
// it completes.
// Because active sessions list can be accessed from multiple threads,
//
// we guard it with a mutex to avoid data corruption.
std::unique_lock<std::mutex> lock(active_sessions_guard_);
active_sessions_[s->id] = s;
lock.unlock();
boost::asio::async_connect(
s->socket.next_layer(),
results.begin(),
......@@ -68,10 +58,6 @@ Client::on_connect(std::shared_ptr<Session> s, boost::system::error_code ec)
return s->on_failure(s->id, ec);
}
// Check if the request is already cancelled and we shouldn't move forward.
if (s->is_cancelled)
return on_request_complete(s);
// Perform the SSL handshake
s->socket.async_handshake(
boost::asio::ssl::stream_base::client,
......@@ -86,10 +72,6 @@ Client::on_handshake(std::shared_ptr<Session> s, boost::system::error_code ec)
return s->on_failure(s->id, ec);
}
// Check if the request is already cancelled and we shouldn't move forward.
if (s->is_cancelled)
return on_request_complete(s);
boost::beast::http::async_write(s->socket,
s->request,
std::bind(&Client::on_write,
......@@ -111,9 +93,6 @@ Client::on_write(std::shared_ptr<Session> s,
return s->on_failure(s->id, ec);
}
if (s->is_cancelled)
return on_request_complete(s);
// Receive the HTTP response
http::async_read(
s->socket,
......@@ -148,16 +127,6 @@ Client::do_request(std::shared_ptr<Session> s)
std::placeholders::_2));
}
void
Client::cancel_request(RequestID request_id)
{
std::unique_lock<std::mutex> lock(active_sessions_guard_);
auto it = active_sessions_.find(request_id);
if (it != active_sessions_.end())
it->second->is_cancelled = true;
}
void
Client::remove_session(std::shared_ptr<Session> s)
{
......@@ -182,15 +151,6 @@ Client::remove_session(std::shared_ptr<Session> s)
// TODO: propagate the error.
std::cout << "shutdown: " << ec.message() << std::endl;
});
// Remove the session from the map of active sessions.
std::unique_lock<std::mutex> lock(active_sessions_guard_);
auto it = active_sessions_.find(s->id);
if (it != active_sessions_.end())
active_sessions_.erase(it);
lock.unlock();
}
void
......@@ -198,16 +158,7 @@ Client::on_request_complete(std::shared_ptr<Session> s)
{
remove_session(s);
boost::system::error_code ec;
if (s->error_code == 0 && s->is_cancelled) {
ec = boost::asio::error::operation_aborted;
s->on_failure(s->id, ec);
return;
} else {
ec = s->error_code;
}
boost::system::error_code ec(s->error_code);
s->on_success(s->id, s->parser.get(), ec);
}
......
......@@ -12,10 +12,11 @@
#include <boost/thread/thread.hpp>
#include <json.hpp>
#include <mtx/requests.hpp>
#include <mtx/responses.hpp>
#include "crypto.hpp"
#include "errors.hpp"
#include "mtx/requests.hpp"
#include "mtx/responses.hpp"
#include "session.hpp"
#include "utils.hpp"
......@@ -45,12 +46,8 @@ public:
//! Wait for the client to close.
void close();
//! Cancels the request.
void cancel_request(RequestID request_id);
//! Make a new request.
void do_request(std::shared_ptr<Session> session);
//! Return the number of pending requests.
int active_sessions() const { return active_sessions_.size(); }
//! Add an access token.
void set_access_token(const std::string &token) { access_token_ = token; }
//! Retrieve the access token.
......@@ -267,10 +264,6 @@ private:
boost::asio::io_service ios_;
//! Keeps tracks for the active sessions.
std::map<RequestID, std::shared_ptr<Session>> active_sessions_;
//! Used to synchronize access to `active_sessions_`.
std::mutex active_sessions_guard_;
//! Used to prevent the event loop from shutting down.
std::unique_ptr<boost::asio::io_service::work> work_;
//! Worker threads for the requests.
......
......@@ -36,7 +36,6 @@ struct Session
, id{id}
, on_success{on_success}
, on_failure{on_failure}
, is_cancelled{false}
{
parser.header_limit(8192);
parser.body_limit(1 * 1024 * 1024 * 1024); // 1 GiB
......@@ -61,8 +60,6 @@ struct Session
SuccessCallback on_success;
//! Function to be called when the request fails.
FailureCallback on_failure;
//! Whether or not the request has been cancelled.
std::atomic_bool is_cancelled;
};
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment