Skip to content

Commit

Permalink
Add debug messages to the win32 event loop test
Browse files Browse the repository at this point in the history
It still fails sometimes so let's see what the logs will have to say
with these additional debugs.
  • Loading branch information
MiKom committed Jul 11, 2024
1 parent b4dbbc6 commit 0e9280a
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ TEST_CASE("Wait for events")
auto serverFunction = [&mutex, &cond, &ready, &dataToSend, &boundPort]() {
SOCKET serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (serverSocket == INVALID_SOCKET) {
spdlog::error("Cannot create server socket");
SPDLOG_ERROR("Cannot create server socket");
}
sockaddr_in ad;
ad.sin_family = AF_INET;
Expand All @@ -138,9 +138,11 @@ TEST_CASE("Wait for events")
if (foundPort == 0)
return;

SPDLOG_INFO("server: listening on port {}", foundPort);

ret = listen(serverSocket, SOMAXCONN);
if (ret == SOCKET_ERROR) {
spdlog::error("Listen error");
SPDLOG_ERROR("Listen error: {}", WSAGetLastError());
}

// Send info to the client that we're ready
Expand All @@ -156,9 +158,14 @@ TEST_CASE("Wait for events")

if (clientSocket != INVALID_SOCKET) {
ret = send(clientSocket, dataToSend.c_str(), dataToSend.size() + 1, 0);
if (ret != SOCKET_ERROR) {
SPDLOG_INFO("Server sent {} bytes", ret);
} else {
SPDLOG_ERROR("Error while sending data: {}", WSAGetLastError());
}
closesocket(clientSocket);
} else {
spdlog::error("invalid socket from accept");
SPDLOG_ERROR("invalid socket from accept");
}
};
// Start the server
Expand Down Expand Up @@ -189,6 +196,8 @@ TEST_CASE("Wait for events")
readNotifier.triggered.connect([&dataReceived](int fd) {
char buf[128] = {};
recv(fd, buf, 128, 0);
const int recvSize = recv(fd, buf, 128, 0);
SPDLOG_INFO("socket test: received {} bytes from the server", recvSize);
dataReceived = std::string(buf);
});
loop.registerNotifier(&readNotifier);
Expand Down

0 comments on commit 0e9280a

Please sign in to comment.