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

Function networkLoop

3ds/source/server.cpp:304–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302 }
303
304 static void networkLoop()
305 {
306 struct sockaddr_in clientAddr;
307 u32 clientLen = sizeof(clientAddr);
308
309 // Set server socket to non-blocking
310 fcntl(serverSocket, F_SETFL, fcntl(serverSocket, F_GETFL, 0) | O_NONBLOCK);
311
312 serverIsRunning.store(true);
313 while (serverRunning.test_and_set()) {
314 s32 clientSocket = accept(serverSocket, (struct sockaddr*)&clientAddr, &clientLen);
315
316 if (clientSocket >= 0) {
317 // Set client socket to blocking for simpler sending
318 fcntl(clientSocket, F_SETFL, fcntl(clientSocket, F_GETFL, 0) & ~O_NONBLOCK);
319 handleHttpRequest(clientSocket);
320 close(clientSocket);
321 }
322 else if (errno != EAGAIN && errno != EWOULDBLOCK) {
323 Logging::error("accept() failed on the transfer socket with errno {}.", errno);
324 }
325
326 // Prevent 100% CPU usage
327 svcSleepThread(100000000); // 100ms
328 }
329
330 serverIsRunning.store(false);
331 }
332}
333
334void 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