| 236 | } |
| 237 | |
| 238 | result = HttpWebSocketHandshake::acceptServerConnection(connection, transport, acceptStorage); |
| 239 | if (not result) |
| 240 | { |
| 241 | runtime.pump.detach(); |
| 242 | (void)webSocketHub.leave(runtime.hubIndex); |
| 243 | runtime.hubIndex = size_t(-1); |
| 244 | } |
| 245 | return result; |
| 246 | } |
| 247 | |
| 248 | Result assignConnectionMemory(size_t numClients) |
| 249 | { |
| 250 | SC_TRY(clients.resize(numClients)); |
| 251 | SC_TRY(fileStreams.resize(numClients)); |
| 252 | const size_t numWebSocketClients = |
| 253 | maxWebSocketClients == 0 ? numClients : min(numClients, static_cast<size_t>(maxWebSocketClients)); |
| 254 | SC_TRY(webSocketHubClients.resize(numWebSocketClients)); |
| 255 | SC_TRY(webSocketRuntimes.resize(numClients)); |
| 256 | SC_TRY(allReadQueues.resize(numClients * asyncConfiguration.readQueueSize)); |
| 257 | SC_TRY(allWriteQueues.resize(numClients * asyncConfiguration.writeQueueSize)); |
| 258 | SC_TRY(allBuffers.resize(numClients * asyncConfiguration.buffersQueueSize)); |
| 259 | SC_TRY(allHeaders.resizeWithoutInitializing(numClients * asyncConfiguration.headerBytesLength)); |
| 260 | SC_TRY(allStreams.resizeWithoutInitializing(numClients * asyncConfiguration.streamBytesLength)); |
| 261 | HttpConnectionsPool::Memory memory; |
| 262 | memory.allBuffers = allBuffers; |
| 263 | memory.allReadQueue = allReadQueues; |
| 264 | memory.allWriteQueue = allWriteQueues; |
| 265 | memory.allHeaders = allHeaders; |
| 266 | memory.allStreams = allStreams; |
| 267 | SC_TRY(memory.assignTo(asyncConfiguration, clients.toSpan())); |
| 268 | SC_TRY(webSocketHub.init(webSocketHubClients.toSpan())); |
| 269 | return Result(true); |
| 270 | } |
| 271 | |
| 272 | Result runtimeResize() |
| 273 | { |
| 274 | const size_t numClients = |
| 275 | max(static_cast<size_t>(maxClients), httpServer.getConnections().getHighestActiveConnection()); |
| 276 | SC_TRY(assignConnectionMemory(numClients)); |
| 277 | SC_TRY(httpServer.resize(clients.toSpan())); |
| 278 | return Result(true); |
| 279 | } |
| 280 | }; |
| 281 | |
| 282 | Result saneMain(Span<const StringSpan> args) |
| 283 | { |
| 284 | AsyncWebServerExample sample; |
| 285 | SocketNetworking::initNetworking(); |
| 286 | Console::tryAttachingToParentConsole(); |
| 287 | Console console; |
| 288 | StringPath currentDirPath; |
| 289 | StringView directory; |
| 290 | StringView interface; |
| 291 | uint16_t port = static_cast<uint16_t>(sample.port); |
| 292 | |
| 293 | globalConsole = &console; |
| 294 | CommandLineOption cmdOptions[10]; |
| 295 | cmdOptions[0].longName = "directory"; |
no test coverage detected