MCPcopy Create free account
hub / github.com/FEX-Emu/FEX / HandleSocketData

Function HandleSocketData

Source/Tools/FEXServer/ProcessPipe.cpp:264–381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262}
263
264void HandleSocketData(fasio::tcp_socket& Socket) {
265 std::vector<uint8_t> Data(1500);
266
267 // Get the current number of FDs of the process before we start handling sockets.
268 GetMaxFDs();
269
270 fasio::mutable_buffer buffer = {std::as_writable_bytes(std::span(Data))};
271
272 {
273 fasio::error ec;
274
275 auto Read = Socket.read_some(buffer, ec);
276 if (ec == fasio::error::success) {
277 assert(Read >= sizeof(FEXServerClient::FEXServerRequestPacket));
278 buffer = {buffer.Data.subspan(0, Read)};
279 } else if (ec == fasio::error::eof) {
280 return;
281 } else {
282 perror("read");
283 return;
284 }
285 }
286
287 while (buffer.size() > 0) {
288 FEXServerClient::FEXServerRequestPacket* Req = reinterpret_cast<FEXServerClient::FEXServerRequestPacket*>(Data.data());
289 switch (Req->Header.Type) {
290 case FEXServerClient::PacketType::TYPE_KILL:
291 Reactor.stop_async();
292 buffer += sizeof(FEXServerClient::FEXServerRequestPacket::BasicRequest);
293 break;
294 case FEXServerClient::PacketType::TYPE_GET_LOG_FD: {
295 if (Logger::LogThreadRunning()) {
296 int fds[2] {};
297 pipe2(fds, 0);
298 // 0 = Read
299 // 1 = Write
300 Logger::AppendLogFD(fds[0]);
301
302 SendFDSuccessPacket(Socket, fds[1]);
303
304 // Close the write side now, doesn't matter to us
305 close(fds[1]);
306
307 // Check if we need to increase the FD limit.
308 ++NumFilesOpened;
309 CheckRaiseFDLimit();
310 } else {
311 // Log thread isn't running. Let FEXInterpreter know it can't have one.
312 SendEmptyErrorPacket(Socket);
313 }
314
315 buffer += sizeof(FEXServerClient::FEXServerRequestPacket::Header);
316 break;
317 }
318 case FEXServerClient::PacketType::TYPE_GET_ROOTFS_PATH: {
319 const fextl::string& MountFolder = SquashFS::GetMountFolder();
320
321 FEXServerClient::FEXServerResultPacket Res {

Callers 1

InitializeServerSocketFunction · 0.85

Calls 15

GetMaxFDsFunction · 0.85
LogThreadRunningFunction · 0.85
AppendLogFDFunction · 0.85
SendFDSuccessPacketFunction · 0.85
closeFunction · 0.85
CheckRaiseFDLimitFunction · 0.85
SendEmptyErrorPacketFunction · 0.85
ChainedFunction · 0.85
pidfd_openFunction · 0.85
getpidFunction · 0.85
EFmtFunction · 0.85
read_someMethod · 0.80

Tested by

no test coverage detected