final int actualSendBufSize = channel.getOption(StandardSocketOptions.SO_SNDBUF); if (actualSendBufSize < maxSendBufferSize) { logger.warn("Attempted to set Socket Send Buffer Size to " + maxSendBufferSize
/** * {@inheritDoc} * * Forwards to {@link #delegate}. */ @Override public <U> U getOption(SocketOption<U> name) throws IOException { return delegate.getOption(name); }
@Override public <T> T getOption(SocketOption<T> socketOption) throws IOException { return socketChannel.getOption(socketOption); }
@Override public <T> T getOption(SocketOption<T> socketOption) throws IOException { return socketChannel.getOption(socketOption); }
public <T> T getOption(SocketOption<T> name) throws IOException { return delegate.getOption(name); } public Set<SocketOption<?>> supportedOptions() { return delegate.supportedOptions(); }
private void checkBuffers(int i, Pipe<NetPayloadSchema> pipe, SocketChannel socketChannel) { if (!bufferChecked[i]) { try { int minBufSize = Math.max(workingBuffers.length>8 ? pipe.maxVarLen*4 : pipe.sizeOfBlobRing, socketChannel.getOption(StandardSocketOptions.SO_SNDBUF)); if (null==workingBuffers[i] || workingBuffers[i].capacity()<minBufSize) { workingBuffers[i] = ByteBuffer.allocateDirect(minBufSize); } bufferChecked[i] = true; } catch (ClosedChannelException cce) { if (null==workingBuffers[i]) { workingBuffers[i] = ByteBuffer.allocateDirect(workingBuffers.length>8 ? pipe.maxVarLen*4 : pipe.sizeOfBlobRing); } bufferChecked[i] = true; } catch (IOException e) { throw new RuntimeException(e); } } }
private ClientConnection checkBuffers(int i, Pipe<NetPayloadSchema> pipe, ClientConnection cc) { if (!bufferChecked[i]) { if (null!=cc) { SocketChannel sc = cc.getSocketChannel(); if (null!=sc) { try { int minBufSize = Math.max(pipe.sizeOfBlobRing/4, //buffer should be as large as the full pipe so more can accumulate sc.getOption(StandardSocketOptions.SO_SNDBUF)); if (null!=buffers[i]) { logger.trace("buffer is {} and must be at least {}",buffers[i].capacity(), minBufSize); } if (null==buffers[i] || buffers[i].capacity()<minBufSize) { //logger.info("new direct buffer of size {} created old one was too small.",minBufSize); buffers[i] = ByteBuffer.allocateDirect(minBufSize); } bufferChecked[i] = true; } catch (IOException e) { return null; } } } } return cc; }
/** * Open the underlying socket connection. * @throws ConnectException if the socket fails to connect. * @throws IOException if the underlying input and output streams raise an error. */ @Override public void open() throws ConnectException, IOException { channel = SocketChannel.open(); channel.setOption(StandardSocketOptions.SO_RCVBUF, IO.SOCKET_BUFFER_SIZE); channel.setOption(StandardSocketOptions.SO_SNDBUF, IO.SOCKET_BUFFER_SIZE); channel.setOption(StandardSocketOptions.TCP_NODELAY, IO.SOCKET_TCP_NODELAY); channel.setOption(StandardSocketOptions.SO_KEEPALIVE, IO.SOCKET_KEEPALIVE); final InetSocketAddress address = new InetSocketAddress(host, port); channel.connect(address); if (!blocking) { while (!channel.finishConnect()) { try { Thread.sleep(1L); } catch (@SuppressWarnings("unused") final InterruptedException e) { } } } opened = true; if (debugEnabled) log.debug("getReceiveBufferSize() = {}", channel.getOption(StandardSocketOptions.SO_RCVBUF)); }
receiveBufferSize = 1+testChannel.getOption(StandardSocketOptions.SO_RCVBUF);
this.recBufferSize = this.getSocketChannel().getOption(StandardSocketOptions.SO_RCVBUF);