Skip to content

Commit

Permalink
Merge pull request #901 from hyperxor/more_traces_to_peer_to_debug
Browse files Browse the repository at this point in the history
More traces to Peer class, http server test and change id generation
  • Loading branch information
kiplingw authored Apr 13, 2021
2 parents 361f2ff + 2bcdf0c commit a998e29
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/pistache/peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace Pistache
private:
void associateTransport(Transport* transport);
Transport* transport() const;
static size_t getUniqueId();

Transport* transport_ = nullptr;
Fd fd_ = -1;
Expand Down
13 changes: 8 additions & 5 deletions src/common/peer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ namespace Pistache
{
namespace Tcp
{

std::atomic<size_t> idCounter { 0 };

namespace
{
struct ConcretePeer : Peer
Expand All @@ -37,7 +34,7 @@ namespace Pistache
: fd_(fd)
, addr(addr)
, ssl_(ssl)
, id_(idCounter++)
, id_(getUniqueId())
{ }

Peer::~Peer()
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
4 changes: 2 additions & 2 deletions tests/http_server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a998e29

Please sign in to comment.