Unverified Commit a998e296 authored by Kip's avatar Kip Committed by GitHub

Merge pull request #901 from hyperxor/more_traces_to_peer_to_debug

More traces to Peer class, http server test and change id generation
parents 361f2ff2 2bcdf0cf
......@@ -60,6 +60,7 @@ namespace Pistache
private:
void associateTransport(Transport* transport);
Transport* transport() const;
static size_t getUniqueId();
Transport* transport_ = nullptr;
Fd fd_ = -1;
......
......@@ -19,9 +19,6 @@ namespace Pistache
{
namespace Tcp
{
std::atomic<size_t> idCounter { 0 };
namespace
{
struct ConcretePeer : Peer
......@@ -37,7 +34,7 @@ namespace Pistache
: fd_(fd)
, addr(addr)
, ssl_(ssl)
, id_(idCounter++)
, id_(getUniqueId())
{ }
Peer::~Peer()
......@@ -138,7 +135,7 @@ namespace Pistache
std::ostream& operator<<(std::ostream& os, Peer& peer)
{
const auto& addr = peer.address();
os << "Peer with ID=" << peer.getID() << " (address=" << addr
os << "Peer " << &peer << " (id=" << peer.getID() << ", address=" << addr
<< ", hostname=" << peer.hostname() << ", fd=" << peer.fd() << ")";
return os;
}
......@@ -153,5 +150,11 @@ namespace Pistache
return transport_;
}
size_t Peer::getUniqueId()
{
static std::atomic<size_t> idCounter { 0 };
return idCounter++;
}
} // namespace Tcp
} // namespace Pistache
......@@ -612,13 +612,13 @@ namespace
}
std::string requestAddress = request.address().host();
writer.send(Http::Code::Ok, requestAddress);
std::cout << SERVER_PREFIX << " Sent: `" << requestAddress << "` data to "
std::cout << SERVER_PREFIX << " Sent `" << requestAddress << "` to "
<< *peer << std::endl;
}
void onDisconnection(const std::shared_ptr<Tcp::Peer>& peer) override
{
std::cout << SERVER_PREFIX << " Disconnect from peer " << *peer
std::cout << SERVER_PREFIX << " Disconnect from " << *peer
<< std::endl;
activeConnections.erase(peer->getID());
waitHelper->increment();
......
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