use of com.facebook.stetho.server.SocketLike in project stetho by facebook.
the class LightHttpServer method serve.
public void serve(SocketLike socket) throws IOException {
LeakyBufferedInputStream input = new LeakyBufferedInputStream(socket.getInput(), 1024);
OutputStream output = socket.getOutput();
HttpMessageReader reader = new HttpMessageReader(input);
HttpMessageWriter writer = new HttpMessageWriter(new BufferedOutputStream(output));
SocketLike anotherSocketLike = new SocketLike(socket, input);
LightHttpRequest scratchRequest = new LightHttpRequest();
LightHttpResponse scratchResponse = new LightHttpResponse();
LightHttpRequest request;
// expect the client to just close the connection.
while ((request = readRequestMessage(scratchRequest, reader)) != null) {
final LightHttpResponse response = scratchResponse;
response.reset();
// Note, if we're upgrading to websockets, this will block for the lifetime of the
// websocket session...
boolean keepGoing = dispatchToHandler(anotherSocketLike, request, response);
if (!keepGoing) {
// Orderly shutdown, ignore response and break the loop.
break;
}
writeFullResponse(response, writer, output);
}
}
Aggregations