| 63 | } |
| 64 | |
| 65 | void HttpStreamServer::acceptClients() { |
| 66 | if (!isConnected()) { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | // Accept new clients (non-blocking) |
| 71 | mNativeServer->acceptClients(); |
| 72 | |
| 73 | // Get list of all client IDs |
| 74 | fl::vector<u32> clientIds = mNativeServer->getClientIds(); |
| 75 | |
| 76 | // Process each client's HTTP header if not already done |
| 77 | for (u32 clientId : clientIds) { |
| 78 | ClientState* state = getOrCreateClientState(clientId); |
| 79 | if (!state) { |
| 80 | continue; |
| 81 | } |
| 82 | |
| 83 | // If HTTP headers not exchanged yet, do it now |
| 84 | if (!state->httpHeaderReceived) { |
| 85 | if (readHttpRequestHeader(clientId)) { |
| 86 | // Send HTTP response header |
| 87 | if (!sendHttpResponseHeader(clientId)) { |
| 88 | // Failed to send response, disconnect client |
| 89 | disconnectClient(clientId); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // Clean up disconnected clients |
| 96 | fl::vector<u32> activeClientIds = mNativeServer->getClientIds(); |
| 97 | fl::vector<u32> toRemove; |
| 98 | |
| 99 | for (auto& pair : mClientStates) { |
| 100 | u32 clientId = pair.first; |
| 101 | bool found = false; |
| 102 | for (u32 activeId : activeClientIds) { |
| 103 | if (activeId == clientId) { |
| 104 | found = true; |
| 105 | break; |
| 106 | } |
| 107 | } |
| 108 | if (!found) { |
| 109 | toRemove.push_back(clientId); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | for (u32 clientId : toRemove) { |
| 114 | removeClientState(clientId); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | size_t HttpStreamServer::getClientCount() const { |
| 119 | return mNativeServer ? mNativeServer->getClientCount() : 0; |
no test coverage detected