fix bugs that end connection randomly
This commit is contained in:
parent
487d1660e2
commit
9959d33290
3 changed files with 23 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if(i != bytes.length) {
|
||||
throw new Stop();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
package de.tudbut.tryumph.server.http;
|
||||
|
||||
public class Stop extends RuntimeException {
|
||||
public Stop() {}
|
||||
public Stop(String reason) { super(reason); }
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue