mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
*) Using timeout also to establish a connection
See: http://www.yacy-forum.de/viewtopic.php?t=979&highlight= git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@558 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
36dfb9f686
commit
4335bfe822
|
@ -48,6 +48,7 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PushbackInputStream;
|
import java.io.PushbackInputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
@ -413,25 +414,32 @@ public final class httpc {
|
||||||
if (hostip == null) throw new UnknownHostException(server);
|
if (hostip == null) throw new UnknownHostException(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
// opening the socket
|
// creating a socket
|
||||||
socket = (ssl) ? SSLSocketFactory.getDefault().createSocket(hostip, port)
|
this.socket = (ssl) ? SSLSocketFactory.getDefault().createSocket()
|
||||||
: new Socket(hostip, port);
|
: new Socket();
|
||||||
|
|
||||||
|
// creating a socket address
|
||||||
|
InetSocketAddress address = new InetSocketAddress(hostip, port);
|
||||||
|
|
||||||
|
// trying to establis a connection to the address
|
||||||
|
this.socket.connect(address,timeout);
|
||||||
|
|
||||||
// registering the socket
|
// registering the socket
|
||||||
this.socketOwner = this.registerOpenSocket(socket);
|
this.socketOwner = this.registerOpenSocket(this.socket);
|
||||||
|
|
||||||
// setting socket timeout and keep alive behaviour
|
// setting socket timeout and keep alive behaviour
|
||||||
socket.setSoTimeout(timeout); // waiting time for write
|
this.socket.setSoTimeout(timeout); // waiting time for read
|
||||||
//socket.setSoLinger(true, timeout); // waiting time for read
|
//socket.setSoLinger(true, timeout);
|
||||||
socket.setKeepAlive(true); //
|
this.socket.setKeepAlive(true); //
|
||||||
|
|
||||||
// getting input and output streams
|
// getting input and output streams
|
||||||
clientInput = new PushbackInputStream(socket.getInputStream());
|
this.clientInput = new PushbackInputStream(this.socket.getInputStream());
|
||||||
clientOutput = socket.getOutputStream();
|
this.clientOutput = this.socket.getOutputStream();
|
||||||
|
|
||||||
// if we reached this point, we should have a connection
|
// if we reached this point, we should have a connection
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
if (this.socket != null) {
|
if (this.socket != null) {
|
||||||
this.unregisterOpenSocket(this.socket,this.socketOwner);
|
httpc.unregisterOpenSocket(this.socket,this.socketOwner);
|
||||||
}
|
}
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
this.socketOwner = null;
|
this.socketOwner = null;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user