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

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

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

Socket.getSendBufferSize介绍

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

代码示例

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

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

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

/**
 * Gets the socket's sendBufferSize.
 * 
 * @return the size of the buffer for the socket OutputStream, -1 if the value
 * has not been set and the socket has not been opened
 * 
 * @throws SocketException if an error occurs while getting the socket value
 * 
 * @see Socket#getSendBufferSize()
 */
public int getSendBufferSize() throws SocketException {
  if (socket == null) {
    return -1;
  } else {
    return socket.getSendBufferSize();
  }
}

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

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

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

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

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

private void configureSocket(Socket socket) throws SocketException {
  socket.setTcpNoDelay(true);
  socket.setSendBufferSize(this.socketBufferSize);
  if(socket.getReceiveBufferSize() != this.socketBufferSize)
    logger.debug("Requested socket receive buffer size was " + this.socketBufferSize
           + " bytes but actual size is " + socket.getReceiveBufferSize() + " bytes.");
  if(socket.getSendBufferSize() != this.socketBufferSize)
    logger.debug("Requested socket send buffer size was " + this.socketBufferSize
           + " bytes but actual size is " + socket.getSendBufferSize() + " bytes.");
}

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

/**
 * @param sock Socket.
 * @return Buffered stream wrapping socket stream.
 * @throws IOException If failed.
 */
final BufferedOutputStream socketStream(Socket sock) throws IOException {
  int bufSize = sock.getSendBufferSize();
  return bufSize > 0 ? new BufferedOutputStream(sock.getOutputStream(), bufSize) :
    new BufferedOutputStream(sock.getOutputStream());
}

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

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

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

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

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

public ProtobufChannel(final Set<InetSocketAddress> locators, String username, String password,
  String keyStorePath, String trustStorePath, String protocols, String ciphers,
  ValueSerializer serializer) throws GeneralSecurityException, IOException {
 this.serializer = serializer;
 socket = connectToAServer(locators, username, password, keyStorePath, trustStorePath, protocols,
   ciphers);
 output = new BufferedOutputStream(socket.getOutputStream(), socket.getSendBufferSize());
}

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

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

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

@Override
protected void connect(SelectionKey selectionKey) throws IOException {
  if(!checkTimeout()) {
    return;
  }
  if(socketChannel.finishConnect() == false) {
    return;
  }
  if(logger.isDebugEnabled()) {
    // check buffer sizes you often don't get out what you put in!
    if(socketChannel.socket().getReceiveBufferSize() != this.socketBufferSize) {
      logger.debug("Requested socket receive buffer size was " + this.socketBufferSize
             + " bytes but actual size is "
             + socketChannel.socket().getReceiveBufferSize() + " bytes.");
    }
    if(socketChannel.socket().getSendBufferSize() != this.socketBufferSize) {
      logger.debug("Requested socket send buffer size was " + this.socketBufferSize
             + " bytes but actual size is "
             + socketChannel.socket().getSendBufferSize() + " bytes.");
    }
  }
  addClientRequest(clientRequest, timeoutMs, 0);
}

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

private void initializeTransientFields(Socket socket, ClientProxyMembershipID pid, boolean ip,
  byte cc, Version vers) {
 this._socket = socket;
 this.proxyID = pid;
 this.connected = true;
 {
  int bufSize = 1024;
  try {
   bufSize = _socket.getSendBufferSize();
   if (bufSize < 1024) {
    bufSize = 1024;
   }
  } catch (SocketException ignore) {
  }
  this._commBuffer = ServerConnection.allocateCommBuffer(bufSize, socket);
 }
 this._remoteHostAddress = socket.getInetAddress().getHostAddress();
 this.isPrimary = ip;
 this.clientConflation = cc;
 this.clientVersion = vers;
}

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

private void recordSocketCreation(SocketDestination dest, Socket socket) throws SocketException {
  int numCreated = created.incrementAndGet();
  logger.debug("Created socket " + numCreated + " for " + dest.getHost() + ":"
         + dest.getPort() + " using protocol " + dest.getRequestFormatType().getCode());
  // check buffer sizes--you often don't get out what you put in!
  int sendBufferSize = socket.getSendBufferSize();
  int receiveBufferSize = socket.getReceiveBufferSize();
  if(receiveBufferSize != this.socketBufferSize)
    logger.debug("Requested socket receive buffer size was " + this.socketBufferSize
           + " bytes but actual size is " + receiveBufferSize + " bytes.");
  if(sendBufferSize != this.socketBufferSize)
    logger.debug("Requested socket send buffer size was " + this.socketBufferSize
           + " bytes but actual size is " + sendBufferSize + " bytes.");
}

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

/**
 * Returns the size of the send buffer on this connection's socket.
 */
int getSendBufferSize() {
 int result = this.sendBufferSize;
 if (result != -1) {
  return result;
 }
 try {
  result = getSocket().getSendBufferSize();
 } catch (SocketException ignore) {
  // just return a default
  result = this.owner.getConduit().tcpBufferSize;
 }
 this.sendBufferSize = result;
 return result;
}

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

@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: 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: 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;
  }
},

相关文章

微信公众号

最新文章

更多