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

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

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

Socket.getReceiveBufferSize介绍

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

代码示例

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

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

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

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

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

private int getBufferSize(SocketChannel channel) {
 int size = 1024;
 try {
  size = channel.socket().getReceiveBufferSize();
 } catch (SocketException e) {
  // use default size
 }
 return size;
}

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

@Override
public int getReceiveBufferSize() {
  try {
    return javaSocket.getReceiveBufferSize();
  } 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/zookeeper

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

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

private Socket applySettings(Socket s) throws IOException {
  if(logger.isDebugEnabled())
    logger.debug("Attempting to set socket receive buffer of "
           + this.socketReceiveBufferSize + " bytes");
  s.setReceiveBufferSize(socketReceiveBufferSize);
  s.setSoTimeout(socketTimeout);
  if(logger.isDebugEnabled())
    logger.info("Actually set socket receive buffer to " + s.getReceiveBufferSize()
          + " bytes");
  return s;
}

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

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

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

public int getReceiveBufferSize() {
  try {
    return socket.getReceiveBufferSize();
  } 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: 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/activemq

public Bridge(Socket socket, URI target) throws Exception {
  receiveSocket = socket;
  sendSocket = createSocket(target);
  if (receiveBufferSize > 0) {
    sendSocket.setReceiveBufferSize(receiveBufferSize);
  }
  sendSocket.connect(new InetSocketAddress(target.getHost(), target.getPort()));
  linkWithThreads(receiveSocket, sendSocket);
  LOG.info("proxy connection " + sendSocket + ", receiveBufferSize=" + sendSocket.getReceiveBufferSize());
}

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

public void run() {
  try {
    while(!socket.isClosed()) {
      pause.get().await();
      try {
        Socket source = socket.accept();
        pause.get().await();
        if (receiveBufferSize > 0) {
          source.setReceiveBufferSize(receiveBufferSize);
        }
        LOG.info("accepted " + source + ", receiveBufferSize:" + source.getReceiveBufferSize());
        synchronized(connections) {
          connections.add(new Bridge(source, target));
        }
      } catch (SocketTimeoutException expected) {
      }
    }
  } catch (Exception e) {
    LOG.debug("acceptor: finished for reason: " + e.getLocalizedMessage());
  }
}

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

result = option.cast(Integer.valueOf(conduit.getAndSetReadTimeout(value == null ? 0 : Options.READ_TIMEOUT.cast(value).intValue())));
} else if (option == Options.RECEIVE_BUFFER) {
  result = option.cast(Integer.valueOf(conduit.getSocketChannel().socket().getReceiveBufferSize()));
  conduit.getSocketChannel().socket().setReceiveBufferSize(Options.RECEIVE_BUFFER.cast(value).intValue());
} else if (option == Options.SEND_BUFFER) {

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

public ServerQueueStatus connect(EndpointManager endpointManager, ServerLocation location,
  ClientSideHandshake handshake, int socketBufferSize, int handshakeTimeout, int readTimeout,
  CommunicationMode communicationMode, GatewaySender sender, SocketCreator sc)
  throws IOException {
 theSocket = sc.connectForClient(location.getHostName(), location.getPort(), handshakeTimeout,
   socketBufferSize);
 theSocket.setTcpNoDelay(true);
 theSocket.setSendBufferSize(socketBufferSize);
 // Verify buffer sizes
 verifySocketBufferSize(socketBufferSize, theSocket.getReceiveBufferSize(), "receive");
 verifySocketBufferSize(socketBufferSize, theSocket.getSendBufferSize(), "send");
 theSocket.setSoTimeout(handshakeTimeout);
 out = theSocket.getOutputStream();
 in = theSocket.getInputStream();
 this.status = handshake.handshakeWithServer(this, location, communicationMode);
 commBuffer = ServerConnection.allocateCommBuffer(socketBufferSize, theSocket);
 if (sender != null) {
  commBufferForAsyncRead = ServerConnection.allocateCommBuffer(socketBufferSize, theSocket);
 }
 theSocket.setSoTimeout(readTimeout);
 endpoint = endpointManager.referenceEndpoint(location, this.status.getMemberId());
 this.connectFinished = true;
 this.endpoint.getStats().incConnections(1);
 return status;
}

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

private void createIoFilter(SocketChannel channel, boolean clientSocket) throws IOException {
 if (getConduit().useSSL() && channel != null) {
  InetSocketAddress address = (InetSocketAddress) channel.getRemoteAddress();
  SSLEngine engine =
    getConduit().getSocketCreator().createSSLEngine(address.getHostName(), address.getPort());
  if (!clientSocket) {
   engine.setWantClientAuth(true);
   engine.setNeedClientAuth(true);
  }
  int packetBufferSize = engine.getSession().getPacketBufferSize();
  if (inputBuffer == null
    || (inputBuffer.capacity() < packetBufferSize)) {
   // TLS has a minimum input buffer size constraint
   if (inputBuffer != null) {
    Buffers.releaseReceiveBuffer(inputBuffer, getConduit().getStats());
   }
   inputBuffer = Buffers.acquireReceiveBuffer(packetBufferSize, getConduit().getStats());
  }
  if (channel.socket().getReceiveBufferSize() < packetBufferSize) {
   channel.socket().setReceiveBufferSize(packetBufferSize);
  }
  if (channel.socket().getSendBufferSize() < packetBufferSize) {
   channel.socket().setSendBufferSize(packetBufferSize);
  }
  ioFilter = getConduit().getSocketCreator().handshakeSSLSocketChannel(channel, engine,
    getConduit().idleConnectionTimeout, clientSocket, inputBuffer, getConduit().getStats());
 } else {
  ioFilter = new NioPlainEngine();
 }
}

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

SocketChannel socketChannel = (SocketChannel) key.channel();
log.debug("Created socket with SO_RCVBUF = {}, SO_SNDBUF = {}, SO_TIMEOUT = {} to node {}",
    socketChannel.socket().getReceiveBufferSize(),
    socketChannel.socket().getSendBufferSize(),
    socketChannel.socket().getSoTimeout(),

相关文章