| 1205 | } |
| 1206 | |
| 1207 | static Result createPendingServerInstance(StringSpan pipeName, const NamedPipeServerOptions& options, |
| 1208 | bool firstInstance, FileDescriptor& pendingConnection) |
| 1209 | { |
| 1210 | const wchar_t* nullTerminatedName = pipeName.getNullTerminatedNative(); |
| 1211 | |
| 1212 | DWORD openMode = PIPE_ACCESS_DUPLEX; |
| 1213 | if (not options.connectionOptions.blocking) |
| 1214 | { |
| 1215 | openMode |= FILE_FLAG_OVERLAPPED; |
| 1216 | } |
| 1217 | if (firstInstance) |
| 1218 | { |
| 1219 | openMode |= FILE_FLAG_FIRST_PIPE_INSTANCE; |
| 1220 | } |
| 1221 | |
| 1222 | DWORD maxPendingConnections = options.maxPendingConnections; |
| 1223 | if (maxPendingConnections == 0) |
| 1224 | { |
| 1225 | maxPendingConnections = 1; |
| 1226 | } |
| 1227 | if (maxPendingConnections > PIPE_UNLIMITED_INSTANCES) |
| 1228 | { |
| 1229 | maxPendingConnections = PIPE_UNLIMITED_INSTANCES; |
| 1230 | } |
| 1231 | |
| 1232 | const DWORD pipeMode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT; |
| 1233 | |
| 1234 | HANDLE handle = |
| 1235 | ::CreateNamedPipeW(nullTerminatedName, openMode, pipeMode, maxPendingConnections, 65536, 65536, 0, nullptr); |
| 1236 | SC_TRY_MSG(handle != INVALID_HANDLE_VALUE, "NamedPipeServer::create CreateNamedPipeW failed"); |
| 1237 | |
| 1238 | return Result(pendingConnection.assign(handle)); |
| 1239 | } |
| 1240 | } // namespace |
| 1241 | |
| 1242 | SC::Result SC::NamedPipeServer::create(StringSpan pipeName, NamedPipeServerOptions pipeOptions) |