mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
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:
parent
00dab81077
commit
3cb9cdc9be
|
@ -41,6 +41,7 @@
|
||||||
package de.anomic.http;
|
package de.anomic.http;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -1638,35 +1639,43 @@ public final class httpc {
|
||||||
/**
|
/**
|
||||||
* This method writes the input stream to either another output stream
|
* This method writes the input stream to either another output stream
|
||||||
* or a file or both.
|
* 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 procOS
|
||||||
* @param file
|
* @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
|
// this writes the input stream to either another output stream or
|
||||||
// a file or both.
|
// a file or both.
|
||||||
FileOutputStream bufferOS = null;
|
FileOutputStream bufferOS = null;
|
||||||
|
if (file != null) try {
|
||||||
|
bufferOS = new FileOutputStream(file);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
file = null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (file != null) bufferOS = new FileOutputStream(file);
|
InputStream is = this.getContentInputStream();
|
||||||
if (procOS == null) {
|
if (procOS == null) {
|
||||||
serverFileUtils.writeX(this.getContentInputStream(), null, bufferOS);
|
serverFileUtils.writeX(is, null, bufferOS);
|
||||||
} else if (procOS instanceof OutputStream) {
|
} 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);
|
//writeContentX(httpc.this.clientInput, this.gzip, this.responseHeader.contentLength(), procOS, bufferOS);
|
||||||
} else if (procOS instanceof Writer) {
|
} else if (procOS instanceof Writer) {
|
||||||
String charSet = this.responseHeader.getCharacterEncoding();
|
String charSet = this.responseHeader.getCharacterEncoding();
|
||||||
if (charSet == null) charSet = httpHeader.DEFAULT_CHARSET;
|
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 {
|
} else {
|
||||||
throw new IllegalArgumentException("Invalid procOS object type '" + procOS.getClass().getName() + "'");
|
throw new IllegalArgumentException("Invalid procOS object type '" + procOS.getClass().getName() + "'");
|
||||||
}
|
}
|
||||||
} finally {
|
} catch (IOException e) {}
|
||||||
if (bufferOS != null) {
|
|
||||||
bufferOS.flush();
|
if (bufferOS != null) {
|
||||||
|
try {
|
||||||
|
bufferOS.flush();
|
||||||
bufferOS.close();
|
bufferOS.close();
|
||||||
if (file.length() == 0) file.delete();
|
} catch (IOException e) {}
|
||||||
}
|
if (file.length() == 0) file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -900,7 +900,7 @@ public final class httpdFileHandler {
|
||||||
try {out.flush();}catch (Exception e) {}
|
try {out.flush();}catch (Exception e) {}
|
||||||
if (((String)requestHeader.get(httpHeader.CONNECTION, "close")).indexOf("keep-alive") == -1) {
|
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
|
// 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?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,40 +111,46 @@ public final class serverFileUtils {
|
||||||
return total;
|
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];
|
byte[] buffer = new byte[2048];
|
||||||
int l;
|
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 (procOS != null) procOS.write(buffer, 0, l);
|
||||||
if (bufferOS != null) bufferOS.write(buffer, 0, l);
|
if (bufferOS != null) bufferOS.write(buffer, 0, l);
|
||||||
}
|
} catch (IOException e) {break;}
|
||||||
|
|
||||||
// flush the streams
|
// flush the streams
|
||||||
if (procOS != null) procOS.flush();
|
if (procOS != null) try { procOS.flush(); } catch (IOException e) {}
|
||||||
if (bufferOS != null) bufferOS.flush();
|
if (bufferOS != null) try { bufferOS.flush(); } catch (IOException e) {}
|
||||||
buffer = null;
|
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];
|
char[] buffer = new char[2048];
|
||||||
int l;
|
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 (procOS != null) procOS.write(buffer, 0, l);
|
||||||
if (bufferOS != null) bufferOS.write(buffer, 0, l);
|
if (bufferOS != null) bufferOS.write(buffer, 0, l);
|
||||||
}
|
} catch (IOException e) {break;}
|
||||||
|
|
||||||
// flush the streams
|
// flush the streams
|
||||||
if (procOS != null) procOS.flush();
|
if (procOS != null) try { procOS.flush(); } catch (IOException e) {}
|
||||||
if (bufferOS != null) bufferOS.flush();
|
if (bufferOS != null) try { bufferOS.flush(); } catch (IOException e) {}
|
||||||
buffer = null;
|
buffer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeX(InputStream source, String inputCharset, Writer procOS, OutputStream bufferOS, String outputCharset) throws IOException {
|
public static void writeX(InputStream source, String inputCharset, Writer procOS, OutputStream bufferOS, String outputCharset) {
|
||||||
InputStreamReader sourceReader = new InputStreamReader(source,inputCharset);
|
try {
|
||||||
OutputStreamWriter bufferOSWriter = (bufferOS==null)?null:new OutputStreamWriter(bufferOS,outputCharset);
|
InputStreamReader sourceReader = new InputStreamReader(source, inputCharset);
|
||||||
writeX(sourceReader,procOS,bufferOSWriter);
|
OutputStreamWriter bufferOSWriter = (bufferOS == null) ? null : new OutputStreamWriter(bufferOS,outputCharset);
|
||||||
|
writeX(sourceReader, procOS, bufferOSWriter);
|
||||||
|
} catch (IOException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -298,7 +298,6 @@ public class yacyCore {
|
||||||
protected class publishThread extends Thread {
|
protected class publishThread extends Thread {
|
||||||
private int added;
|
private int added;
|
||||||
private yacySeed seed;
|
private yacySeed seed;
|
||||||
private Exception error;
|
|
||||||
private final serverSemaphore sync;
|
private final serverSemaphore sync;
|
||||||
private final List syncList;
|
private final List syncList;
|
||||||
|
|
||||||
|
@ -312,7 +311,6 @@ public class yacyCore {
|
||||||
|
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
this.added = 0;
|
this.added = 0;
|
||||||
this.error = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void run() {
|
public final void run() {
|
||||||
|
@ -333,7 +331,6 @@ public class yacyCore {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.logSevere("publishThread: error with target seed " + seed.toString() + ": " + e.getMessage(), e);
|
log.logSevere("publishThread: error with target seed " + seed.toString() + ": " + e.getMessage(), e);
|
||||||
this.error = e;
|
|
||||||
} finally {
|
} finally {
|
||||||
this.syncList.add(this);
|
this.syncList.add(this);
|
||||||
this.sync.V();
|
this.sync.V();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user