MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / onNewClient

Method onNewClient

Libraries/Http/HttpAsyncServer.cpp:160–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158{
159 SocketDescriptor acceptedClient;
160 Result accepted = result.moveTo(acceptedClient);
161 if (not accepted)
162 {
163 if (onError.isValid())
164 {
165 onError(accepted);
166 }
167 return;
168 }
169 HttpConnection::ID idx;
170 // Activation always succeeds because we pause asyncAccept when the there are not available clients
171 SC_HTTP_ASSERT_RELEASE(connections.activateNew(idx));
172
173 HttpConnection& client = static_cast<HttpConnection&>(connections.getConnection(idx));
174
175 SC_HTTP_ASSERT_RELEASE(client.readableSocketStream.request.isFree());
176 SC_HTTP_ASSERT_RELEASE(client.writableSocketStream.request.isFree());
177
178 client.socket = move(acceptedClient);
179 SC_HTTP_TRUST_RESULT(client.readableSocketStream.init(client.buffersPool, *eventLoop, client.socket));
180 SC_HTTP_TRUST_RESULT(client.writableSocketStream.init(client.buffersPool, *eventLoop, client.socket));
181 client.resetTransportStreams();
182 client.readableSocketStream.setAutoDestroy(true);
183 client.writableSocketStream.setAutoDestroy(false); // needed for keep-alive logic
184
185 Result setup = beginTransportConnection(client);
186 if (not setup)
187 {
188 if (onError.isValid())
189 {
190 onError(setup);
191 }
192 closeAsync(client);
193 }
194
195 // Only reactivate asyncAccept if there are available clients (otherwise it's being reactivated in closeAsync)
196 result.reactivateRequest(connections.getNumActiveConnections() < connections.getNumTotalConnections());
197}
198

Callers

nothing calls this directly

Calls 9

onErrorFunction · 0.85
activateNewMethod · 0.80
isFreeMethod · 0.80
resetTransportStreamsMethod · 0.80
reactivateRequestMethod · 0.80
moveToMethod · 0.45
isValidMethod · 0.45
initMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected