MCPcopy Create free account
hub / github.com/BernardoGiordano/Checkpoint / networkLoop

Function networkLoop

switch/source/server.cpp:333–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331 }
332
333 void networkLoop(void*)
334 {
335 struct sockaddr_in clientAddr;
336 u32 clientLen = sizeof(clientAddr);
337
338 fcntl(serverSocket, F_SETFL, fcntl(serverSocket, F_GETFL, 0) | O_NONBLOCK);
339
340 serverIsRunning.store(true);
341 while (serverRunning.test_and_set()) {
342 s32 clientSocket = accept(serverSocket, (struct sockaddr*)&clientAddr, &clientLen);
343 if (clientSocket >= 0) {
344 fcntl(clientSocket, F_SETFL, fcntl(clientSocket, F_GETFL, 0) & ~O_NONBLOCK);
345 handleHttpRequest(clientSocket);
346 close(clientSocket);
347 }
348 else if (errno != EAGAIN && errno != EWOULDBLOCK) {
349 Logging::error("accept() failed on the log server socket with errno {}.", errno);
350 }
351 svcSleepThread(100'000'000ULL); // 100ms; don't peg a core
352 }
353
354 serverIsRunning.store(false);
355 }
356}
357
358void Server::registerHandler(const std::string& path, Server::HttpHandler handler)

Callers

nothing calls this directly

Calls 4

acceptFunction · 0.85
errorFunction · 0.85
storeMethod · 0.80
handleHttpRequestFunction · 0.70

Tested by

no test coverage detected