MCPcopy Create free account
hub / github.com/FlagBrew/PKSM / networkLoop

Function networkLoop

3ds/source/utils/server.cpp:92–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90 }
91
92 static void networkLoop()
93 {
94 struct sockaddr_in clientAddr;
95 u32 clientLen = sizeof(clientAddr);
96
97 // Set server socket to non-blocking
98 fcntl(serverSocket, F_SETFL, fcntl(serverSocket, F_GETFL, 0) | O_NONBLOCK);
99
100 while (serverRunning.test_and_set())
101 {
102 s32 clientSocket = accept(serverSocket, (struct sockaddr*)&clientAddr, &clientLen);
103
104 if (clientSocket >= 0)
105 {
106 // Set client socket to blocking for simpler sending
107 fcntl(clientSocket, F_SETFL, fcntl(clientSocket, F_GETFL, 0) & ~O_NONBLOCK);
108 handleHttpRequest(clientSocket);
109 close(clientSocket);
110 }
111 else if (errno != EAGAIN)
112 {
113 // FIXME do something
114 }
115
116 // Prevent 100% CPU usage
117 svcSleepThread(100000000); // 100ms
118 }
119 }
120}
121
122void Server::registerHandler(const std::string& path, Server::HttpHandler handler)

Callers

nothing calls this directly

Calls 2

acceptFunction · 0.85
handleHttpRequestFunction · 0.85

Tested by

no test coverage detected