本文整理汇总了Java中java.net.Socket.getSoTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.getSoTimeout方法的具体用法?Java Socket.getSoTimeout怎么用?Java Socket.getSoTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.Socket
的用法示例。
在下文中一共展示了Socket.getSoTimeout方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: discardStream
import java.net.Socket; //导入方法依赖的package包/类
/**
* Discards the response body so that the connection can be reused. This
* needs to be done judiciously, since it delays the current request in
* order to speed up a potential future request that may never occur.
*
* <p>A stream may be discarded to encourage response caching (a response
* cannot be cached unless it is consumed completely) or to enable connection
* reuse.
*/
private static boolean discardStream(HttpEngine httpEngine, InputStream responseBodyIn) {
Connection connection = httpEngine.connection;
if (connection == null) return false;
Socket socket = connection.getSocket();
if (socket == null) return false;
try {
int socketTimeout = socket.getSoTimeout();
socket.setSoTimeout(DISCARD_STREAM_TIMEOUT_MILLIS);
try {
Util.skipAll(responseBodyIn);
return true;
} finally {
socket.setSoTimeout(socketTimeout);
}
} catch (IOException e) {
return false;
}
}
示例2: isHealthy
import java.net.Socket; //导入方法依赖的package包/类
boolean isHealthy(boolean doExtensiveChecks) {
if (!connected) {
return false;
}
Socket socket;
BufferedSource source;
synchronized (this) {
socket = this.socket;
source = this.source;
}
if (socket == null ||
source == null ||
socket.isClosed() ||
socket.isInputShutdown() ||
socket.isOutputShutdown()) {
return false;
}
if (doExtensiveChecks) {
try {
int readTimeout = socket.getSoTimeout();
try {
socket.setSoTimeout(1);
return !source.exhausted();
} finally {
socket.setSoTimeout(readTimeout);
}
} catch (SocketTimeoutException ignored) {
ignored.printStackTrace();
// Read timed out; socket is good.
} catch (IOException e) {
return false; // Couldn't read; socket is closed.
}
}
return true;
}
示例3: getSocketTimeout
import java.net.Socket; //导入方法依赖的package包/类
@Override
public int getSocketTimeout() {
final Socket socket = this.socketHolder.get();
if (socket != null) {
try {
return socket.getSoTimeout();
} catch (final SocketException ignore) {
return -1;
}
} else {
return -1;
}
}
示例4: fillInputBuffer
import java.net.Socket; //导入方法依赖的package包/类
private int fillInputBuffer(final int timeout) throws IOException {
final Socket socket = this.socketHolder.get();
final int oldtimeout = socket.getSoTimeout();
try {
socket.setSoTimeout(timeout);
return this.inbuffer.fillBuffer();
} finally {
socket.setSoTimeout(oldtimeout);
}
}
示例5: HandShake
import java.net.Socket; //导入方法依赖的package包/类
/**
* HandShake Constructor used by server side connection
*/
public HandShake(Socket sock, int timeout, DistributedSystem sys, Version clientVersion,
byte communicationMode) throws IOException, AuthenticationRequiredException {
this.clientVersion = clientVersion;
this.system = sys;
// SocketChannel sc = sock.getChannel();
/*
* if (sc != null) { } else
*/ {
int soTimeout = -1;
try {
soTimeout = sock.getSoTimeout();
sock.setSoTimeout(timeout);
InputStream is = sock.getInputStream();
int valRead = is.read();
// this.code = (byte)is.read();
if (valRead == -1) {
throw new EOFException(
LocalizedStrings.HandShake_HANDSHAKE_EOF_REACHED_BEFORE_CLIENT_CODE_COULD_BE_READ
.toLocalizedString());
}
this.code = (byte) valRead;
if (this.code != REPLY_OK) {
throw new IOException(
LocalizedStrings.HandShake_HANDSHAKE_REPLY_CODE_IS_NOT_OK.toLocalizedString());
}
try {
DataInputStream dis = new DataInputStream(is);
DataOutputStream dos = new DataOutputStream(sock.getOutputStream());
this.clientReadTimeout = dis.readInt();
if (clientVersion.compareTo(Version.CURRENT) < 0) {
// versioned streams allow object serialization code to deal with older clients
dis = new VersionedDataInputStream(dis, clientVersion);
dos = new VersionedDataOutputStream(dos, clientVersion);
}
this.id = ClientProxyMembershipID.readCanonicalized(dis);
// Note: credentials should always be the last piece in handshake for
// Diffie-Hellman key exchange to work
if (clientVersion.compareTo(Version.GFE_603) >= 0) {
setOverrides(new byte[] {dis.readByte()});
} else {
setClientConflation(dis.readByte());
}
// Hitesh
if (this.clientVersion.compareTo(Version.GFE_65) < 0
|| communicationMode == Acceptor.GATEWAY_TO_GATEWAY) {
this.credentials = readCredentials(dis, dos, sys);
} else {
this.credentials = this.readCredential(dis, dos, sys);
}
} catch (IOException ioe) {
this.code = -2;
throw ioe;
} catch (ClassNotFoundException cnfe) {
this.code = -3;
throw new IOException(
LocalizedStrings.HandShake_CLIENTPROXYMEMBERSHIPID_CLASS_COULD_NOT_BE_FOUND_WHILE_DESERIALIZING_THE_OBJECT
.toLocalizedString());
}
} finally {
if (soTimeout != -1) {
try {
sock.setSoTimeout(soTimeout);
} catch (IOException ignore) {
}
}
}
}
}
示例6: readClientVersion
import java.net.Socket; //导入方法依赖的package包/类
private static Version readClientVersion(ServerConnection connection)
throws IOException, VersionException {
Socket socket = connection.getSocket();
int timeout = connection.getHandShakeTimeout();
int soTimeout = -1;
try {
soTimeout = socket.getSoTimeout();
socket.setSoTimeout(timeout);
InputStream is = socket.getInputStream();
short clientVersionOrdinal = Version.readOrdinalFromInputStream(is);
if (clientVersionOrdinal == -1) {
throw new EOFException(
LocalizedStrings.ServerHandShakeProcessor_HANDSHAKEREADER_EOF_REACHED_BEFORE_CLIENT_VERSION_COULD_BE_READ
.toLocalizedString());
}
Version clientVersion = null;
try {
clientVersion = Version.fromOrdinal(clientVersionOrdinal, true);
} catch (UnsupportedVersionException uve) {
// Allows higher version of wan site to connect to server
if (connection.getCommunicationMode() == Acceptor.GATEWAY_TO_GATEWAY
&& !(clientVersionOrdinal == Version.NOT_SUPPORTED_ORDINAL)) {
return Acceptor.VERSION;
} else {
SocketAddress sa = socket.getRemoteSocketAddress();
String sInfo = "";
if (sa != null) {
sInfo = " Client: " + sa.toString() + ".";
}
throw new UnsupportedVersionException(uve.getMessage() + sInfo);
}
}
if (!clientVersion.compatibleWith(Acceptor.VERSION)) {
throw new IncompatibleVersionException(clientVersion, Acceptor.VERSION);// we can throw this
// to restrict
} // Backward Compatibilty Support to limited no of versions
return clientVersion;
} finally {
if (soTimeout != -1) {
try {
socket.setSoTimeout(soTimeout);
} catch (IOException ignore) {
}
}
}
}
示例7: SocketInputStream
import java.net.Socket; //导入方法依赖的package包/类
/**
* Same as SocketInputStream(socket.getChannel(), socket.getSoTimeout())
* :<br><br>
*
* Create a new input stream with the given timeout. If the timeout
* is zero, it will be treated as infinite timeout. The socket's
* channel will be configured to be non-blocking.
* @see SocketInputStream#SocketInputStream(ReadableByteChannel, long)
*
* @param socket should have a channel associated with it.
* @throws IOException
*/
public SocketInputStream(Socket socket) throws IOException {
this(socket.getChannel(), socket.getSoTimeout());
}