try to fix connection problem, possible cause for wrong junior status and non-passive passive peers:

the YaCy client treats disconnections during data transmissions as error and discards all data transmitted so far
this did not happen so far until I removed a delay time at the end of the daemon session which prevented this case.
To fix this problem, disconnections during transmissions are not treated as error now, which means that end-of-transmissions
with sudden disconnections are not a cause for peer diconnections any more. To be nice to non-updated peers, the sleep time
at the end of server sessions is also re-enabled.


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4105 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
orbiter 2007-09-23 17:31:29 +00:00
parent 00dab81077
commit 3cb9cdc9be
4 changed files with 41 additions and 29 deletions

View File

@ -41,6 +41,7 @@
package de.anomic.http;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -1638,35 +1639,43 @@ public final class httpc {
/**
* This method writes the input stream to either another output stream
* or a file or both.
* In case that an exception occurrs, the stream reading is just teminated
* and content received so far is returned
*
* @param procOS
* @param file
* @throws IOException
*/
public void writeContent(Object procOS, File file) throws IOException {
public void writeContent(Object procOS, File file) {
// this writes the input stream to either another output stream or
// a file or both.
FileOutputStream bufferOS = null;
if (file != null) try {
bufferOS = new FileOutputStream(file);
} catch (FileNotFoundException e) {
file = null;
}
try {
if (file != null) bufferOS = new FileOutputStream(file);
InputStream is = this.getContentInputStream();
if (procOS == null) {
serverFileUtils.writeX(this.getContentInputStream(), null, bufferOS);
serverFileUtils.writeX(is, null, bufferOS);
} else if (procOS instanceof OutputStream) {
serverFileUtils.writeX(this.getContentInputStream(), (OutputStream) procOS, bufferOS);
serverFileUtils.writeX(is, (OutputStream) procOS, bufferOS);
//writeContentX(httpc.this.clientInput, this.gzip, this.responseHeader.contentLength(), procOS, bufferOS);
} else if (procOS instanceof Writer) {
String charSet = this.responseHeader.getCharacterEncoding();
if (charSet == null) charSet = httpHeader.DEFAULT_CHARSET;
serverFileUtils.writeX(this.getContentInputStream(), charSet, (Writer)procOS, bufferOS, charSet);
serverFileUtils.writeX(is, charSet, (Writer) procOS, bufferOS, charSet);
} else {
throw new IllegalArgumentException("Invalid procOS object type '" + procOS.getClass().getName() + "'");
}
} finally {
if (bufferOS != null) {
bufferOS.flush();
} catch (IOException e) {}
if (bufferOS != null) {
try {
bufferOS.flush();
bufferOS.close();
if (file.length() == 0) file.delete();
}
} catch (IOException e) {}
if (file.length() == 0) file.delete();
}
}

View File

@ -900,7 +900,7 @@ public final class httpdFileHandler {
try {out.flush();}catch (Exception e) {}
if (((String)requestHeader.get(httpHeader.CONNECTION, "close")).indexOf("keep-alive") == -1) {
// wait a little time until everything closes so that clients can read from the streams/sockets
//try {Thread.sleep(200);} catch (InterruptedException e) {} // FIXME: is this necessary?
try {Thread.sleep(50);} catch (InterruptedException e) {} // FIXME: is this necessary?
}
}
}

View File

@ -111,40 +111,46 @@ public final class serverFileUtils {
return total;
}
public static void writeX(InputStream source, OutputStream procOS, OutputStream bufferOS) throws IOException {
public static void writeX(InputStream source, OutputStream procOS, OutputStream bufferOS) {
byte[] buffer = new byte[2048];
int l;
while ((l = source.read(buffer, 0, buffer.length)) >= 0) {
while (true) try {
l = source.read(buffer, 0, buffer.length);
if (l <= 0) break;
if (procOS != null) procOS.write(buffer, 0, l);
if (bufferOS != null) bufferOS.write(buffer, 0, l);
}
} catch (IOException e) {break;}
// flush the streams
if (procOS != null) procOS.flush();
if (bufferOS != null) bufferOS.flush();
if (procOS != null) try { procOS.flush(); } catch (IOException e) {}
if (bufferOS != null) try { bufferOS.flush(); } catch (IOException e) {}
buffer = null;
}
public static void writeX(Reader source, Writer procOS, Writer bufferOS) throws IOException {
public static void writeX(Reader source, Writer procOS, Writer bufferOS) {
char[] buffer = new char[2048];
int l;
while ((l = source.read(buffer, 0, buffer.length)) >= 0) {
while (true) try{
l = source.read(buffer, 0, buffer.length);
if (l <= 0) break;
if (procOS != null) procOS.write(buffer, 0, l);
if (bufferOS != null) bufferOS.write(buffer, 0, l);
}
} catch (IOException e) {break;}
// flush the streams
if (procOS != null) procOS.flush();
if (bufferOS != null) bufferOS.flush();
if (procOS != null) try { procOS.flush(); } catch (IOException e) {}
if (bufferOS != null) try { bufferOS.flush(); } catch (IOException e) {}
buffer = null;
}
public static void writeX(InputStream source, String inputCharset, Writer procOS, OutputStream bufferOS, String outputCharset) throws IOException {
InputStreamReader sourceReader = new InputStreamReader(source,inputCharset);
OutputStreamWriter bufferOSWriter = (bufferOS==null)?null:new OutputStreamWriter(bufferOS,outputCharset);
writeX(sourceReader,procOS,bufferOSWriter);
public static void writeX(InputStream source, String inputCharset, Writer procOS, OutputStream bufferOS, String outputCharset) {
try {
InputStreamReader sourceReader = new InputStreamReader(source, inputCharset);
OutputStreamWriter bufferOSWriter = (bufferOS == null) ? null : new OutputStreamWriter(bufferOS,outputCharset);
writeX(sourceReader, procOS, bufferOSWriter);
} catch (IOException e) {}
}

View File

@ -298,7 +298,6 @@ public class yacyCore {
protected class publishThread extends Thread {
private int added;
private yacySeed seed;
private Exception error;
private final serverSemaphore sync;
private final List syncList;
@ -312,7 +311,6 @@ public class yacyCore {
this.seed = seed;
this.added = 0;
this.error = null;
}
public final void run() {
@ -333,7 +331,6 @@ public class yacyCore {
}
} catch (Exception e) {
log.logSevere("publishThread: error with target seed " + seed.toString() + ": " + e.getMessage(), e);
this.error = e;
} finally {
this.syncList.add(this);
this.sync.V();