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

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

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

Socket.getSoLinger介绍

[英]Returns this socket's SocketOptions#SO_LINGER timeout in seconds, or -1 for no linger (i.e. close will return immediately).
[中]返回此套接字的SocketOptions#SO#LINGER timeout(秒),或-1表示无延迟(即关闭将立即返回)。

代码示例

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

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

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

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

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

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

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

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

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

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

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

public int getSoLinger() {
  try {
    return socket.getSoLinger();
  } catch (SocketException e) {
    throw new ChannelException(e);
  }
}

代码示例来源: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: wildfly/wildfly

public <T> T getOption(final Option<T> option) throws IOException {
  if (option == Options.CLOSE_ABORT) {
    return option.cast(Boolean.valueOf(conduit.getSocketChannel().socket().getSoLinger() == 0));
  } else if (option == Options.IP_TRAFFIC_CLASS) {
    return option.cast(Integer.valueOf(conduit.getSocketChannel().socket().getTrafficClass()));
  } else if (option == Options.KEEP_ALIVE) {
    return option.cast(Boolean.valueOf(conduit.getSocketChannel().socket().getKeepAlive()));
  } else if (option == Options.READ_TIMEOUT) {
    return option.cast(Integer.valueOf(conduit.getReadTimeout()));
  } else if (option == Options.RECEIVE_BUFFER) {
    return option.cast(Integer.valueOf(conduit.getSocketChannel().socket().getReceiveBufferSize()));
  } else if (option == Options.SEND_BUFFER) {
    return option.cast(Integer.valueOf(conduit.getSocketChannel().socket().getSendBufferSize()));
  } else if (option == Options.TCP_NODELAY) {
    return option.cast(Boolean.valueOf(conduit.getSocketChannel().socket().getTcpNoDelay()));
  } else if (option == Options.TCP_OOB_INLINE) {
    return option.cast(Boolean.valueOf(conduit.getSocketChannel().socket().getOOBInline()));
  } else if (option == Options.WRITE_TIMEOUT) {
    return option.cast(Integer.valueOf(conduit.getWriteTimeout()));
  } else {
    return null;
  }
}

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

public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
  T result;
  if (option == Options.CLOSE_ABORT) {
    result = option.cast(Boolean.valueOf(conduit.getSocketChannel().socket().getSoLinger() == 0));
    conduit.getSocketChannel().socket().setSoLinger(Options.CLOSE_ABORT.cast(value, Boolean.FALSE).booleanValue(), 0);
  } else if (option == Options.IP_TRAFFIC_CLASS) {

代码示例来源: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() + ']');
      sockRef.set(sock);
      sock.getOutputStream().write(
        new byte[(sock.getSendBufferSize() + sock.getReceiveBufferSize()) * 2]);
      assert false : "Message has been written.";
    }
    catch (IOException e) {
      X.println("Caught expected exception: " + e);
      e.printStackTrace();
    }
    finally {
      U.closeQuiet(sock);
    }
    return null;
  }
},

代码示例来源: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);
    }
  }
},

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

@Nullable @Override public Object call() throws Exception {
    ServerSocket srvSock = null;
    Socket sock = null;
    try {
      srvSock = new ServerSocket(60000, 0, addr);
      sock = srvSock.accept();
      X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
        ", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() + ']');
      sock.setKeepAlive(true);
      sock.setSoTimeout(2000);
      sock.setSendBufferSize(256 * 1024);
      X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
        ", sndBuf=" + sock.getSendBufferSize() + ", rcvBuf=" + sock.getReceiveBufferSize() + ']');
      while (!done.get())
        X.println("Read from socket: " + sock.getInputStream().read());
      return null;
    }
    finally {
      U.closeQuiet(srvSock);
      U.closeQuiet(sock);
    }
  }
},

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

@Nullable @Override public Object call() throws Exception {
    ServerSocket srvSock = null;
    Socket sock = null;
    try {
      srvSock = new ServerSocket(60000, 0, addr);
      sock = srvSock.accept();
      X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
        ", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() +
        ", NODELAY=" + sock.getTcpNoDelay() + ']');
      sock.setSoTimeout(2000);
      sock.setTcpNoDelay(true);
      X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
        ", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() +
        ", NODELAY=" + sock.getTcpNoDelay() + ']');
      sock.getInputStream().read();
    }
    catch (IOException e) {
      X.println("Caught expected exception: " + e);
      e.printStackTrace();
    }
    finally {
      U.closeQuiet(srvSock);
      U.closeQuiet(sock);
    }
    return null;
  }
},

代码示例来源: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() + ']');
      sock.setKeepAlive(true);
      sock.setSoTimeout(2000);
      sock.setSendBufferSize(256 * 1024);
      X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
        ", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() + ']');
      int i = 0;
      while (!done.get()) {
        sock.getOutputStream().write(++i);
        sock.getOutputStream().flush();
        X.println("Wrote to socket: " + i);
        X.println("Socket connected: " + sock.isConnected());
        X.println("Socket keep alive: " + sock.getKeepAlive());
        U.sleep(1000);
      }
      return null;
    }
    finally {
      U.closeQuiet(sock);
    }
  }
},

代码示例来源:origin: stackoverflow.com

return delegate.getSoLinger();

代码示例来源:origin: stackoverflow.com

return delegate.getSoLinger();

代码示例来源:origin: stackoverflow.com

return delegate.getSoLinger();

代码示例来源:origin: commons-net/commons-net

/**
 * Returns the current SO_LINGER timeout of the currently opened socket.
 * <p>
 * @return The current SO_LINGER timeout.  If SO_LINGER is disabled returns
 *         -1.
 * @throws SocketException If the operation fails.
 * @throws NullPointerException if the socket is not currently open
 */
public int getSoLinger() throws SocketException
{
  return _socket_.getSoLinger();
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

Assert.assertEquals(12345, socket.getSoLinger());
Assert.assertEquals(54321, socket.getSoTimeout());

代码示例来源:origin: org.apache.logging.log4j/log4j-core

Assert.assertEquals(12345, socket.getSoLinger());
Assert.assertEquals(54321, socket.getSoTimeout());

相关文章