Skip to content

Commit

Permalink
Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed Oct 26, 2024
1 parent 4b4f695 commit dd5284b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,24 +1096,30 @@ void Server::Receive(float timeout)
return std::max(0.0f, timeout_us - (porting::getTimeUs() - t0));
};

std::cerr << "Server::Receive with timeout = " << timeout_us << " us" << std::endl;

NetworkPacket pkt;
session_t peer_id;
for (;;) {
pkt.clear();
peer_id = 0;
try {
float remus = remaining_time_us();
u64 timeout_ms = ((u32)remus + 999) / 1000;
std::cerr << " ReceiveTimeoutMs with remaining time = " << remus << " us; timeout = " << timeout_ms << " ms ";
// Round up since the target step length is the minimum step length,
// we only have millisecond precision and we don't want to busy-wait by calling
// ReceiveTimeoutMs(.., 0) repeatedly.
// Also be sure we don't wait if the remaining time is zero/negative.
if (!m_con->ReceiveTimeoutMs(&pkt,
((u32)remaining_time_us() + 999) / 1000)) {
if (!m_con->ReceiveTimeoutMs(&pkt, timeout_ms)) {
std::cerr << " -> no packet" << std::endl;
// No incoming data.
if (remaining_time_us() > 0.0f)
continue;
else
break;
}
std::cerr << " -> got packet" << std::endl;

peer_id = pkt.getPeerId();
m_packet_recv_counter->increment();
Expand Down

0 comments on commit dd5284b

Please sign in to comment.