MCPcopy Create free account
hub / github.com/ddnet/ddnet / Init

Method Init

src/engine/shared/fifo.cpp:14–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include <cstdlib>
13
14void CFifo::Init(IConsole *pConsole, const char *pFifoFile, int Flag)
15{
16 m_File = -1;
17
18 m_pConsole = pConsole;
19 m_IsInit = true;
20 if(pFifoFile[0] == '\0')
21 return;
22
23 str_copy(m_aFilename, pFifoFile);
24 m_Flag = Flag;
25
26 bool IsFifo;
27 if(mkfifo(m_aFilename, 0600) == 0)
28 {
29 struct stat Attribute;
30 if(stat(m_aFilename, &Attribute) == 0)
31 {
32 IsFifo = S_ISFIFO(Attribute.st_mode);
33 }
34 else
35 {
36 log_warn("fifo", "Failed to stat fifo '%s' (%d '%s')", m_aFilename, errno, strerror(errno));
37 IsFifo = false;
38 }
39 }
40 else
41 {
42 log_warn("fifo", "Failed to create fifo '%s' (%d '%s')", m_aFilename, errno, strerror(errno));
43 IsFifo = false;
44 }
45 if(!IsFifo)
46 {
47 log_warn("fifo", "File '%s' is not a fifo, removing", m_aFilename);
48 if(fs_remove(m_aFilename) != 0)
49 {
50 log_error("fifo", "Failed to remove non-fifo '%s'", m_aFilename); // details logged in fs_remove
51 return;
52 }
53 if(mkfifo(m_aFilename, 0600) != 0)
54 {
55 log_error("fifo", "Failed to create fifo '%s' (%d '%s')", m_aFilename, errno, strerror(errno));
56 return;
57 }
58 struct stat Attribute;
59 if(stat(m_aFilename, &Attribute) != 0)
60 {
61 log_error("fifo", "Failed to stat fifo '%s' (%d '%s')", m_aFilename, errno, strerror(errno));
62 return;
63 }
64 if(!S_ISFIFO(Attribute.st_mode))
65 {
66 log_error("fifo", "File '%s' is not a fifo", m_aFilename);
67 return;
68 }
69 }
70
71 m_File = open(m_aFilename, O_RDONLY | O_NONBLOCK);

Callers 5

AcceptClientMethod · 0.45
websocket_createFunction · 0.45
OpenMethod · 0.45
OpenMethod · 0.45

Calls 6

fs_removeFunction · 0.85
windows_utf8_to_wideFunction · 0.85
statClass · 0.70
str_copyFunction · 0.50
str_appendFunction · 0.50

Tested by

no test coverage detected