added timeout for httpd-sockets during read

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3691 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 18 years ago
parent c671d70b2e
commit 24db55a541

@ -111,6 +111,7 @@ public final class httpc {
private static final String vDATE = "20040602";
public static String userAgent;
private static final int terminalMaxLength = 30000;
private static final long terminalMaxTime = 60000;
private static final TimeZone GMTTimeZone = TimeZone.getTimeZone("GMT");
/**
* This string is initialized on loading of this class and contains
@ -1708,7 +1709,7 @@ do upload
}
// reads in the http header, right now, right here
byte[] b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, false);
byte[] b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, terminalMaxTime, false);
if (b == null) {
// the server has meanwhile disconnected
this.statusCode = 503;
@ -1727,7 +1728,7 @@ do upload
if ((this.statusCode==500)&&(this.statusText.equals("status line parse error"))) {
// flush in anything that comes without parsing
while ((b != null) && (b.length != 0)) b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, false);
while ((b != null) && (b.length != 0)) b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, terminalMaxTime, false);
return; // in bad mood
}
@ -1735,13 +1736,13 @@ do upload
if (this.statusCode == 400) {
// bad request
// flush in anything that comes without parsing
while ((b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, false)).length != 0) {}
while ((b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, terminalMaxTime, false)).length != 0) {}
return; // in bad mood
}
// at this point we should have a valid response. read in the header properties
String key = "";
while ((b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, false)) != null) {
while ((b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, terminalMaxTime, false)) != null) {
if (b.length == 0) break;
buffer = new String(b);
buffer=buffer.trim();

@ -1004,7 +1004,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
}
public byte[] readLine() {
return receive(this.in, this.readLineBuffer, serverCore.this.commandMaxLength, false);
return receive(this.in, this.readLineBuffer, serverCore.this.commandMaxLength, serverCore.this.timeout, false);
}
/**
@ -1304,16 +1304,18 @@ public final class serverCore extends serverAbstractThread implements serverThre
}
public static byte[] receive(PushbackInputStream pbis, serverByteBuffer readLineBuffer, int maxSize, boolean logerr) {
public static byte[] receive(PushbackInputStream pbis, serverByteBuffer readLineBuffer, int maxSize, long timeout, boolean logerr) {
// reuse an existing linebuffer
readLineBuffer.reset();
int bufferSize = 0, b = 0;
try {
long start = System.currentTimeMillis();
while ((b = pbis.read()) > 31) {
readLineBuffer.write(b);
if (bufferSize++ > maxSize) break;
if (bufferSize++ > maxSize) break;
if ((System.currentTimeMillis() - start > timeout)) break;
}
// we have catched a possible line end

@ -324,8 +324,7 @@ public final class yacy {
yacyVersion.latestRelease = version;
// read environment
int timeout = Integer.parseInt(sb.getConfig("httpdTimeout", "60000"));
if (timeout < 60000) timeout = 60000;
int timeout = Math.max(20000, Integer.parseInt(sb.getConfig("httpdTimeout", "20000")));
// create some directories
final File htRootPath = new File(homePath, sb.getConfig("htRootPath", "htroot"));

Loading…
Cancel
Save