java.net.Socket.getSoTimeout()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(238)

本文整理了Java中java.net.Socket.getSoTimeout()方法的一些代码示例,展示了Socket.getSoTimeout()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Socket.getSoTimeout()方法的具体详情如下:
包路径:java.net.Socket
类名称:Socket
方法名:getSoTimeout

Socket.getSoTimeout介绍

[英]Returns this socket's SocketOptions#SO_TIMEOUT.
[中]返回此套接字的SocketOptions#SO_TIMEOUT。

代码示例

代码示例来源:origin: aws/aws-sdk-java

@Override
public int getSoTimeout() throws SocketException {
  return sock.getSoTimeout();
}

代码示例来源:origin: robovm/robovm

public int getSocketTimeout() {
  if (this.socket != null) {
    try {
      return this.socket.getSoTimeout();
    } catch (SocketException ignore) {
      return -1;
    }
  } else {
    return -1;
  }
}

代码示例来源:origin: robovm/robovm

public int getSocketTimeout() {
  if (this.socket != null) {
    try {
      return this.socket.getSoTimeout();
    } catch (SocketException ignore) {
      return -1;
    }
  } else {
    return -1;
  }
}

代码示例来源:origin: cmusphinx/sphinx4

/**
 * @return the SO_TIMEOUT of the Socket that this client uses. 0 returns implies that the option is disabled (i.e.,
 * timeout of infinity).
 * @throws SocketException if configuration failed
 */
public int getSoTimeout() throws SocketException {
  if (socket != null) {
    return socket.getSoTimeout();
  } else {
    return 0;
  }
}

代码示例来源:origin: org.postgresql/postgresql

public int getNetworkTimeout() throws IOException {
  return connection.getSoTimeout();
 }
}

代码示例来源:origin: igniterealtime/Smack

@Override
public int getReadTimeout() throws IOException {
  try {
    return this.socket.getSoTimeout();
  }
  catch (SocketException e) {
    throw new IOException("Error on underlying Socket");
  }
}

代码示例来源:origin: netty/netty

@Override
public int getSoTimeout() {
  try {
    return javaSocket.getSoTimeout();
  } catch (IOException e) {
    throw new ChannelException(e);
  }
}

代码示例来源:origin: apache/ignite

/**
   * Returns socket timeout.
   *
   * @throws SQLException if there is an error in the underlying protocol.
   */
  public int timeout() throws SQLException {
    try {
      return sock.getSoTimeout();
    }
    catch (SocketException e) {
      throw new SQLException("Failed to set connection timeout.", SqlStateCode.INTERNAL_ERROR, e);
    }
  }
}

代码示例来源:origin: redisson/redisson

@Override
public int getSoTimeout() {
  try {
    return javaSocket.getSoTimeout();
  } catch (IOException e) {
    throw new ChannelException(e);
  }
}

代码示例来源:origin: apache/zookeeper

/**
 * See {@link Socket#getSoTimeout()}. Calling this method does not trigger mode detection.
 */
@Override
public synchronized int getSoTimeout() throws SocketException {
  return getSocketAllowUnknownMode().getSoTimeout();
}

代码示例来源:origin: apache/geode

public String getSocketString() {
 try {
  return String.valueOf(theSocket.getInetAddress()) + ':' +
    theSocket.getPort() + " timeout: " + theSocket.getSoTimeout();
 } catch (Exception e) {
  return String.format("Error in getSocketString: %s",
    e.getLocalizedMessage());
 }
}

代码示例来源:origin: wildfly/wildfly

@Override
public int getSoTimeout() {
  try {
    return javaSocket.getSoTimeout();
  } catch (IOException e) {
    throw new ChannelException(e);
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Same as <code>getInputStream(socket, socket.getSoTimeout()).</code>
 * <br><br>
 * 
 * @see #getInputStream(Socket, long)
 */
public static SocketInputWrapper getInputStream(Socket socket) 
                     throws IOException {
 return getInputStream(socket, socket.getSoTimeout());
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * 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());
}

代码示例来源:origin: square/okhttp

/** Returns true if this connection is ready to host new streams. */
public boolean isHealthy(boolean doExtensiveChecks) {
 if (socket.isClosed() || socket.isInputShutdown() || socket.isOutputShutdown()) {
  return false;
 }
 if (http2Connection != null) {
  return !http2Connection.isShutdown();
 }
 if (doExtensiveChecks) {
  try {
   int readTimeout = socket.getSoTimeout();
   try {
    socket.setSoTimeout(1);
    if (source.exhausted()) {
     return false; // Stream is exhausted; socket is closed.
    }
    return true;
   } finally {
    socket.setSoTimeout(readTimeout);
   }
  } catch (SocketTimeoutException ignored) {
   // Read timed out; socket is good.
  } catch (IOException e) {
   return false; // Couldn't read; socket is closed.
  }
 }
 return true;
}

代码示例来源:origin: prestodb/presto

/** Returns true if this connection is ready to host new streams. */
public boolean isHealthy(boolean doExtensiveChecks) {
 if (socket.isClosed() || socket.isInputShutdown() || socket.isOutputShutdown()) {
  return false;
 }
 if (http2Connection != null) {
  return !http2Connection.isShutdown();
 }
 if (doExtensiveChecks) {
  try {
   int readTimeout = socket.getSoTimeout();
   try {
    socket.setSoTimeout(1);
    if (source.exhausted()) {
     return false; // Stream is exhausted; socket is closed.
    }
    return true;
   } finally {
    socket.setSoTimeout(readTimeout);
   }
  } catch (SocketTimeoutException ignored) {
   // Read timed out; socket is good.
  } catch (IOException e) {
   return false; // Couldn't read; socket is closed.
  }
 }
 return true;
}

代码示例来源:origin: apache/ignite

/**
   * @param addr Remote address.
   * @param port Remote port.
   * @return Opened socket.
   * @throws IOException If failed.
   */
  private Socket openSocket(InetAddress addr, int port) throws IOException {
    Socket sock = new Socket();

    sock.bind(new InetSocketAddress(InetAddress.getByName("192.168.0.100"), 0));

    sock.connect(new InetSocketAddress(addr, port), 1);

    X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
      ", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() + ']');

    return sock;
  }
}

代码示例来源:origin: apache/ignite

/**  */
@Override protected void writeToSocket(Socket sock,
  OutputStream out,
  TcpDiscoveryAbstractMessage msg,
  long timeout) throws IOException, IgniteCheckedException {
  if (writeToSocketDelay > 0) {
    try {
      U.dumpStack(log, "Before sleep [msg=" + msg + ']');
      Thread.sleep(writeToSocketDelay);
    }
    catch (InterruptedException e) {
      // Nothing to do.
    }
  }
  if (sock.getSoTimeout() >= writeToSocketDelay)
    super.writeToSocket(sock, out, msg, timeout);
  else
    throw new SocketTimeoutException("Write to socket delay timeout exception.");
}

代码示例来源:origin: apache/zookeeper

@Override
  public void run() {
    try {
      byte[] buf = new byte[1024];
      int bytesRead = unifiedSocket.getInputStream().read(buf, 0, 1024);
      // Make sure the settings applied above before the socket was potentially upgraded to
      // TLS still apply.
      Assert.assertEquals(tcpNoDelay, unifiedSocket.getTcpNoDelay());
      Assert.assertEquals(TIMEOUT, unifiedSocket.getSoTimeout());
      Assert.assertEquals(keepAlive, unifiedSocket.getKeepAlive());
      if (bytesRead > 0) {
        byte[] dataFromClient = new byte[bytesRead];
        System.arraycopy(buf, 0, dataFromClient, 0, bytesRead);
        synchronized (dataFromClients) {
          dataFromClients.add(dataFromClient);
        }
      }
      unifiedSocket.getOutputStream().write(dataToClient);
      unifiedSocket.getOutputStream().flush();
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      forceClose(unifiedSocket);
    }
  }
});

代码示例来源:origin: apache/ignite

@Nullable @Override public Object call() throws Exception {
    Socket sock = null;
    try {
      sock = new Socket(addr, 60000);
      X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
        ", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() +
        ", NODELAY=" + sock.getTcpNoDelay() + ']');
      sock.setTcpNoDelay(true);
      X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
        ", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() +
        ", NODELAY=" + sock.getTcpNoDelay() + ']');
      Thread.sleep(10000);
      return null;
    }
    finally {
      U.closeQuiet(sock);
    }
  }
},

相关文章