diff --git a/src/de/tudbut/tryumph/server/http/HTTPRequestReader.java b/src/de/tudbut/tryumph/server/http/HTTPRequestReader.java index 2be4edb..bf0a9d0 100644 --- a/src/de/tudbut/tryumph/server/http/HTTPRequestReader.java +++ b/src/de/tudbut/tryumph/server/http/HTTPRequestReader.java @@ -31,7 +31,7 @@ public class HTTPRequestReader { i = stream.read(); } catch (SocketException e) { if(e.getMessage().equals("Connection reset")) - throw new Stop(); + throw new Stop("Connection closed by client"); throw e; } if(i == -1) { @@ -46,11 +46,21 @@ public class HTTPRequestReader { i = stream.read(bytes); } catch (SocketException e) { if(e.getMessage().equals("Connection reset")) - throw new Stop(); + throw new Stop("Connection closed by client"); throw e; } - if(i != bytes.length) { - throw new Stop(); + while(i != bytes.length) { + try { + int n = stream.read(bytes, i, bytes.length - i); + if(n == 0) { + throw new Stop("0 bytes read"); + } + i += n; + } catch (SocketException e) { + if(e.getMessage().equals("Connection reset")) + throw new Stop("Connection closed by client"); + throw e; + } } return i; } diff --git a/src/de/tudbut/tryumph/server/http/Server.java b/src/de/tudbut/tryumph/server/http/Server.java index b338a32..8b05439 100644 --- a/src/de/tudbut/tryumph/server/http/Server.java +++ b/src/de/tudbut/tryumph/server/http/Server.java @@ -56,7 +56,7 @@ public class Server { throw stop; } catch(Throwable e) { if(e instanceof Nothing) - return; + throw new Stop("Nothing to do"); else { e.printStackTrace(); break; @@ -93,6 +93,12 @@ public class Server { break; } } catch (Stop stop) { + if(stop.getMessage() != null) { + System.out.println("Connection stopped: " + stop.getMessage()); + } + else { + System.out.println("Connection stopped"); + } } try { socket.close(); diff --git a/src/de/tudbut/tryumph/server/http/Stop.java b/src/de/tudbut/tryumph/server/http/Stop.java index 2cd4cd9..e308d22 100644 --- a/src/de/tudbut/tryumph/server/http/Stop.java +++ b/src/de/tudbut/tryumph/server/http/Stop.java @@ -1,4 +1,6 @@ package de.tudbut.tryumph.server.http; public class Stop extends RuntimeException { + public Stop() {} + public Stop(String reason) { super(reason); } }