private void configureSocketChannel(SocketChannel socketChannel, int sendBufferSize, int receiveBufferSize) throws IOException { socketChannel.configureBlocking(false); Socket socket = socketChannel.socket(); socket.setKeepAlive(true); if (sendBufferSize != Selectable.USE_DEFAULT_BUFFER_SIZE) socket.setSendBufferSize(sendBufferSize); if (receiveBufferSize != Selectable.USE_DEFAULT_BUFFER_SIZE) socket.setReceiveBufferSize(receiveBufferSize); socket.setTcpNoDelay(true); }
static void set(Socket socket) throws SocketException { socket.setTcpNoDelay(true); socket.setReceiveBufferSize(20000000); socket.setSendBufferSize(10000000); }
public static void setBuffersSizeIfNecessary(SocketChannel socketChannel, int sendBufferSize, int receiveBufferSize) throws IOException { final Socket socket = socketChannel.socket(); if (sendBufferSize > 0) { socket.setSendBufferSize(sendBufferSize); } if (receiveBufferSize > 0) { socket.setReceiveBufferSize(receiveBufferSize); } } }
+ socketChannel.socket().getPort()); socketChannel.socket().setTcpNoDelay(true); socketChannel.socket().setReuseAddress(true); socketChannel.socket().setKeepAlive(socketKeepAlive); socketChannel.socket().setSendBufferSize(socketBufferSize);
newStream.getSocket().setKeepAlive(requireTCPKeepAlive); newStream.getSocket().setReceiveBufferSize(receiveBufferSize); } else { LOGGER.log(Level.WARNING, "Ignore invalid value for receiveBufferSize: {0}", receiveBufferSize); if (sendBufferSize > -1) { if (sendBufferSize > 0) { newStream.getSocket().setSendBufferSize(sendBufferSize); } else { LOGGER.log(Level.WARNING, "Ignore invalid value for sendBufferSize: {0}", sendBufferSize);
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."); }
@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); } } },
private void applyHints (SocketHints hints) { if (hints != null) { try { socket.setPerformancePreferences(hints.performancePrefConnectionTime, hints.performancePrefLatency, hints.performancePrefBandwidth); socket.setTrafficClass(hints.trafficClass); socket.setTcpNoDelay(hints.tcpNoDelay); socket.setKeepAlive(hints.keepAlive); socket.setSendBufferSize(hints.sendBufferSize); socket.setReceiveBufferSize(hints.receiveBufferSize); socket.setSoLinger(hints.linger, hints.lingerDuration); socket.setSoTimeout(hints.socketTimeout); } catch (Exception e) { throw new GdxRuntimeException("Error setting socket hints.", e); } } }
private void configureSocket(SocketChannel socketChannel) throws IOException { socketChannel.configureBlocking(false); Socket socket = socketChannel.socket(); socket.setTcpNoDelay(noDelay); socket.setReceiveBufferSize(bufSize); socket.setSendBufferSize(bufSize); socket.setReuseAddress(true); }
socket.setKeepAlive(keepAlive != 0); socket.setOOBInline(oobInline != 0); socket.setTcpNoDelay(tcpNoDelay != 0); final int sendBuffer = this.sendBuffer; if (sendBuffer > 0) socket.setSendBufferSize(sendBuffer); final WorkerThread ioThread = worker.getIoThread(hash); final SelectionKey selectionKey = ioThread.registerChannel(accepted);
public static void setupSocket(final Socket sock) throws SocketException { sock.setKeepAlive(true); sock.setReuseAddress(true); sock.setSoTimeout(Constants.READ_TIMEOUT); sock.setSendBufferSize(Math.max(sock.getSendBufferSize(), Constants.BUFFER_LEN * Constants.IO_BUFFERS)); sock.setReceiveBufferSize(Math.max(sock.getReceiveBufferSize(), Constants.BUFFER_LEN * Constants.IO_BUFFERS)); }
protected Connection getConnection(SocketAddress dest) throws Exception { Connection conn=connections.get(dest); if(conn != null) return conn; Socket dest_sock=new Socket(); dest_sock.setSendBufferSize(send_buf_size); dest_sock.setReceiveBufferSize(recv_buf_size); dest_sock.connect(dest); Connection c=connections.putIfAbsent(dest, conn=new Connection(dest_sock).start()); if(c != null) { Util.close(conn); return c; } return conn; }
public Handler(@NotNull SocketChannel socket) throws SocketException { this.socket = socket; socket.socket().setSendBufferSize(256 * 1024); socket.socket().setTcpNoDelay(true); }
@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); } } },
private void applyHints (SocketHints hints) { if (hints != null) { try { socket.setPerformancePreferences(hints.performancePrefConnectionTime, hints.performancePrefLatency, hints.performancePrefBandwidth); socket.setTrafficClass(hints.trafficClass); socket.setTcpNoDelay(hints.tcpNoDelay); socket.setKeepAlive(hints.keepAlive); socket.setSendBufferSize(hints.sendBufferSize); socket.setReceiveBufferSize(hints.receiveBufferSize); socket.setSoLinger(hints.linger, hints.lingerDuration); socket.setSoTimeout(hints.socketTimeout); } catch (Exception e) { throw new GdxRuntimeException("Error setting socket hints.", e); } } }
private void configureSocket(SocketChannel socketChannel) throws IOException { socketChannel.configureBlocking(false); Socket socket = socketChannel.socket(); socket.setTcpNoDelay(noDelay); socket.setReceiveBufferSize(bufSize); socket.setSendBufferSize(bufSize); socket.setReuseAddress(true); }
socket.setKeepAlive(keepAlive != 0); socket.setOOBInline(oobInline != 0); socket.setTcpNoDelay(tcpNoDelay != 0); final int sendBuffer = this.sendBuffer; if (sendBuffer > 0) socket.setSendBufferSize(sendBuffer); final WorkerThread ioThread = worker.getIoThread(hash); ok = true;
public OChannelTextServer(final Socket iSocket, final OContextConfiguration iConfiguration) throws IOException { super(iSocket, iConfiguration); socket.setKeepAlive(true); socket.setPerformancePreferences(1, 2, 0); socket.setSendBufferSize(socketBufferSize); socket.setReceiveBufferSize(socketBufferSize); inStream = new BufferedInputStream(socket.getInputStream(), socketBufferSize); outStream = new BufferedOutputStream(socket.getOutputStream(), socketBufferSize); } }
public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception { local=new InetSocketAddress(local_addr, local_port); remote=new InetSocketAddress(remote_addr, remote_port); srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort(), local.getPort()); System.out.println("Listening on " + srv_sock.getLocalSocketAddress()); acceptor=new Acceptor(); acceptor.start(); sock=new Socket(); //sock.bind(local); sock.setSendBufferSize(SOCK_SEND_BUF_SIZE); sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE); try { sock.connect(remote); output=new DataOutputStream(new BufferedOutputStream(sock.getOutputStream())); System.out.println("Connected to " + sock.getRemoteSocketAddress()); } catch(Throwable t) { System.out.println("Failed connecting to " + remote + ": will only act as server"); } }
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; }