MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / NamedPipeServerThreadProc

Function NamedPipeServerThreadProc

libipc/server.cpp:99–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99DWORD WINAPI NamedPipeServerThreadProc(PVOID lpvParam)
100{
101 //_tprintf(TEXT("\nPipe Server: Main thread awaiting client connection on %s\n"), lpszPipename);
102
103 while (true) {
104 // Wait for the client to connect; if it succeeds,
105 // the function returns a nonzero value. If the function
106 // returns zero, GetLastError returns ERROR_PIPE_CONNECTED.
107
108 auto hPipe = CreateNamedPipe(
109 GetNamedPipeName(false), // pipe name
110 PIPE_ACCESS_DUPLEX, // read/write access
111 PIPE_TYPE_MESSAGE | // message type pipe
112 PIPE_READMODE_MESSAGE | // message-read mode
113 PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS, // blocking mode, local only
114 PIPE_UNLIMITED_INSTANCES, // max. instances
115 CMD_NAMED_PIPE_BUFSIZE, // output buffer size
116 CMD_NAMED_PIPE_BUFSIZE, // input buffer size
117 0, // client time-out
118 NULL); // default security attribute
119
120 if (hPipe == INVALID_HANDLE_VALUE)
121 return 1;
122
123 auto fConnected = ConnectNamedPipe(hPipe, NULL) ?
124 TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
125
126 if (fConnected) {
127 auto con = reinterpret_cast<NamedPipeServerContext*>(lpvParam);
128 con->callback(con->context, hPipe);
129 } else {
130 // The client could not connect, so close the pipe.
131 CloseHandle(hPipe);
132 }
133 }
134
135 return 0;
136}

Callers

nothing calls this directly

Calls 1

GetNamedPipeNameFunction · 0.85

Tested by

no test coverage detected