MCPcopy Create free account
hub / github.com/Warzone2100/warzone2100 / cmdInterfaceThreadInit

Function cmdInterfaceThreadInit

src/stdinreader.cpp:1357–1434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1355}
1356
1357void cmdInterfaceThreadInit()
1358{
1359 if (wz_command_interface() == WZ_Command_Interface::None)
1360 {
1361 return;
1362 }
1363
1364#if defined(HAVE_SYS_EVENTFD_H)
1365 if (quitSignalEventFd == -1)
1366 {
1367 int flags = 0;
1368# if defined(EFD_CLOEXEC)
1369 flags = EFD_CLOEXEC;
1370# endif
1371 quitSignalEventFd = eventfd(0, flags);
1372 }
1373#elif defined(HAVE_UNISTD_H)
1374 if (quitSignalPipeFds[0] == -1 && quitSignalPipeFds[1] == -1)
1375 {
1376 int result = -1;
1377# if defined(HAVE_PIPE2) && defined(O_CLOEXEC)
1378 result = pipe2(quitSignalPipeFds, O_CLOEXEC);
1379# else
1380 result = pipe(quitSignalPipeFds);
1381# endif
1382 if (result == -1)
1383 {
1384 quitSignalPipeFds[0] = -1;
1385 quitSignalPipeFds[1] = -1;
1386 }
1387 }
1388#endif
1389
1390 // initialize output queue (if used)
1391 if (wz_command_interface() != WZ_Command_Interface::StdIn_Interface)
1392 {
1393 cmdInterfaceOutputQueue = std::make_unique<moodycamel::BlockingReaderWriterQueue<CmdInterfaceMessageBuffer>>(1024);
1394 latestWriteBuffer.reserve(maxReserveMessageBufferSize);
1395 }
1396
1397 switch (wz_command_interface())
1398 {
1399 case WZ_Command_Interface::StdIn_Interface:
1400 readFd = STDIN_FILENO;
1401 readFdIsSocket = false;
1402 writeFd = STDERR_FILENO;
1403 writeFdIsNonBlocking = false;
1404 break;
1405 case WZ_Command_Interface::Unix_Socket:
1406 // sets readFd, writeFd, etc as appropriate
1407 if (!cmdInterfaceCreateUnixSocket(wz_cmd_interface_param))
1408 {
1409 // failed (and logged a failure to stderr)
1410 return;
1411 }
1412 break;
1413 default:
1414 return;

Callers 1

wzCmdInterfaceInitFunction · 0.85

Calls 5

wz_command_interfaceFunction · 0.85
wzThreadCreateFunction · 0.85
wzThreadStartFunction · 0.85
reserveMethod · 0.45

Tested by

no test coverage detected