Commit 99feabe8 authored by hyperxor's avatar hyperxor

More traces to Peer class, http server test and change id generation

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