Commit 86ffc350 authored by knowledge4igor's avatar knowledge4igor

Code improvements and fix warnings

parent 5f629561
......@@ -157,9 +157,9 @@ public:
void closeIdleConnections(const std::string& domain);
private:
typedef std::vector<std::shared_ptr<Connection>> Connections;
typedef std::mutex Lock;
typedef std::lock_guard<Lock> Guard;
using Connections = std::vector<std::shared_ptr<Connection>> ;
using Lock = std::mutex;
using Guard = std::lock_guard<Lock>;
mutable Lock connsLock;
std::unordered_map<std::string, Connections> conns;
......@@ -296,7 +296,7 @@ public:
RequestBuilder& body(const std::string& val);
RequestBuilder& body(std::string&& val);
RequestBuilder& timeout(std::chrono::milliseconds value);
RequestBuilder& timeout(std::chrono::milliseconds timeout);
Async::Promise<Response> send();
......@@ -361,8 +361,8 @@ private:
std::atomic<uint64_t> ioIndex;
typedef std::mutex Lock;
typedef std::lock_guard<Lock> Guard;
using Lock = std::mutex;
using Guard = std::lock_guard<Lock>;
Lock queuesLock;
std::unordered_map<std::string, MPMCQueue<std::shared_ptr<Connection::RequestData>, 2048>> requestsQueues;
......@@ -370,7 +370,7 @@ private:
RequestBuilder prepareRequest(const std::string& resource, Http::Method method);
Async::Promise<Response> doRequest(
Http::Request req,
Http::Request request,
std::chrono::milliseconds timeout);
void processRequestQueue();
......
......@@ -26,7 +26,9 @@ class Handler;
class Transport : public Aio::Handler {
public:
Transport(const std::shared_ptr<Tcp::Handler>& handler);
explicit Transport(const std::shared_ptr<Tcp::Handler>& handler);
Transport(const Transport&) = delete;
Transport& operator=(const Transport&) = delete;
void init(const std::shared_ptr<Tcp::Handler>& handler);
......@@ -197,10 +199,12 @@ private:
std::shared_ptr<Peer> peer;
};
using Lock = std::mutex;
using Guard = std::lock_guard<Lock>;
PollableQueue<WriteEntry> writesQueue;
std::unordered_map<Fd, std::deque<WriteEntry> > toWrite;
std::mutex toWriteLock;
std::unordered_map<Fd, std::deque<WriteEntry>> toWrite;
Lock toWriteLock;
PollableQueue<TimerEntry> timersQueue;
std::unordered_map<Fd, TimerEntry> timers;
......
......@@ -436,9 +436,9 @@ Connection::hasTransport() const {
}
void
Connection::handleResponsePacket(const char* buffer, size_t bytes) {
Connection::handleResponsePacket(const char* buffer, size_t totalBytes) {
parser_.feed(buffer, bytes);
parser_.feed(buffer, totalBytes);
if (parser_.parse() == Private::State::Done) {
if (!inflightRequests.empty()) {
auto req = std::move(inflightRequests.front());
......@@ -695,8 +695,8 @@ RequestBuilder::resource(const std::string& val) {
}
RequestBuilder&
RequestBuilder::params(const Uri::Query& params) {
request_.query_ = params;
RequestBuilder::params(const Uri::Query& query) {
request_.query_ = query;
return *this;
}
......
......@@ -56,7 +56,7 @@ Transport::handleNewPeer(const std::shared_ptr<Tcp::Peer>& peer) {
}
int fd = peer->fd();
{
std::lock_guard<std::mutex> lock(toWriteLock);
Guard guard(toWriteLock);
toWrite.emplace(fd, std::deque<WriteEntry>{});
}
}
......@@ -98,7 +98,7 @@ Transport::onReady(const Aio::FdSet& fds) {
auto fd = tag.value();
{
std::lock_guard<std::mutex> lock(toWriteLock);
Guard guard(toWriteLock);
auto it = toWrite.find(fd);
if (it == std::end(toWrite)) {
throw std::runtime_error("Assertion Error: could not find write data");
......@@ -171,7 +171,7 @@ Transport::handlePeerDisconnection(const std::shared_ptr<Peer>& peer) {
{
// Clean up buffers
std::lock_guard<std::mutex> lock(toWriteLock);
Guard guard(toWriteLock);
auto & wq = toWrite[fd];
while (wq.size() > 0) {
auto & entry = wq.front();
......@@ -193,7 +193,7 @@ Transport::asyncWriteImpl(Fd fd)
{
bool stop = false;
while (!stop) {
std::lock_guard<std::mutex> lock(toWriteLock);
Guard guard(toWriteLock);
auto it = toWrite.find(fd);
......@@ -330,7 +330,7 @@ Transport::handleWriteQueue() {
if (!isPeerFd(fd)) continue;
{
std::lock_guard<std::mutex> lock(toWriteLock);
Guard guard(toWriteLock);
toWrite[fd].push_back(std::move(write));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment