Skip to content

Commit

Permalink
Maybe?
Browse files Browse the repository at this point in the history
  • Loading branch information
e3ndr committed Nov 15, 2024
1 parent 6d8a8fa commit 9b893a8
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/main/java/co/casterlabs/rhs/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,16 @@ private void doAccept() {
this.connectedClients.add(clientSocket);

int guessedMtu = guessMtu(clientSocket);
this.executor.execute(() -> this.handle(clientSocket, guessedMtu), TaskType.LIGHT_IO);
String remoteAddress = formatAddress(clientSocket);
this.executor.execute(() -> this.handle(clientSocket, remoteAddress, guessedMtu), TaskType.LIGHT_IO);
} catch (Throwable t) {
this.logger.severe("An error occurred whilst accepting a new connection:\n%s", t);
}
}

@SuppressWarnings("deprecation")
private void handle(Socket clientSocket, int guessedMtu) {
String remoteAddress = formatAddress(clientSocket);

if (clientSocket.isInputShutdown() || clientSocket.isOutputShutdown()) {
this.logger.warn("%s was closed before we could handle it. Oh well.", remoteAddress);
return;
}

private void handle(Socket clientSocket, String remoteAddress, int guessedMtu) {
this.logger.debug("New connection from %s", remoteAddress);

FastLogger sessionLogger = this.logger.createChild("Connection: " + remoteAddress);

TLSVersion tlsVersion = null;
Expand All @@ -189,12 +182,17 @@ private void handle(Socket clientSocket, int guessedMtu) {
}

try {
OverzealousInputStream input = new OverzealousInputStream(clientSocket.getInputStream());
OutputStream output = new MTUOutputStream(clientSocket.getOutputStream(), guessedMtu);

clientSocket.setTcpNoDelay(true);
sessionLogger.trace("Set TCP_NODELAY.");

if (clientSocket.isInputShutdown() || clientSocket.isOutputShutdown()) {
this.logger.warn("%s was closed before we could handle it. Oh well.", remoteAddress);
return;
}

OverzealousInputStream input = new OverzealousInputStream(clientSocket.getInputStream());
OutputStream output = new MTUOutputStream(clientSocket.getOutputStream(), guessedMtu);

while (true) {
// Protocols can override this so we need to reset it every time.
clientSocket.setSoTimeout(RHSConnection.HTTP_PERSISTENT_TIMEOUT * 1000);
Expand Down

0 comments on commit 9b893a8

Please sign in to comment.