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); }
/** * Helper method to set socket options. * * @param sock * Reference to socket */ private void setSockOpts(Socket sock) throws SocketException { sock.setTcpNoDelay(true); sock.setKeepAlive(tcpKeepAlive); sock.setSoTimeout(self.tickTime * self.syncLimit); }
private void createConnection() throws IOException { client = new Socket(hostName, port); client.setKeepAlive(true); client.setTcpNoDelay(true); outputStream = client.getOutputStream(); }
/** * 激活网络 */ private Socket connect(InetSocketAddress address) throws IOException { final Socket socket = new Socket(); socket.setSoTimeout(0); socket.connect(address, _1MIN); socket.setKeepAlive(true); socketWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); socketReader = new BufferedReader(new InputStreamReader(socket.getInputStream())); return socket; }
channel.configureBlocking(false); channel.socket().setSoLinger(false, -1); channel.socket().setReuseAddress(true); channel.socket().setKeepAlive(true); channel.socket().setTcpNoDelay(true);
+ socketChannel.socket().getPort()); socketChannel.socket().setTcpNoDelay(true); socketChannel.socket().setReuseAddress(true); socketChannel.socket().setKeepAlive(socketKeepAlive); socketChannel.socket().setSendBufferSize(socketBufferSize);
@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); } } },
/** * */ public Socket create(String host, int port) throws Exception { final Socket r = new Socket(host, port); r.setKeepAlive(this.keepAlive); r.setTcpNoDelay(this.tcpNoDelay); if(this.receiveBufferSize > 0) r.setReceiveBufferSize(this.receiveBufferSize); return r; }
/** * Creates a socket to {@code dest}, and assigns it to ping_sock. Also assigns ping_input */ protected boolean setupPingSocket(IpAddress dest) { lock.lock(); try { SocketAddress destAddr=new InetSocketAddress(dest.getIpAddress(), dest.getPort()); ping_sock=getSocketFactory().createSocket("jgroups.fd.ping_sock"); Util.bind(ping_sock, bind_addr, client_bind_port, client_bind_port+port_range); ping_sock.setSoLinger(true, 1); ping_sock.setKeepAlive(keep_alive); Util.connect(ping_sock, destAddr, sock_conn_timeout); ping_input=ping_sock.getInputStream(); return true; } catch(Throwable ex) { if(!shuttin_down) log.debug("%s: failed connecting to %s: %s", local_addr, ping_dest != null? ping_dest : dest, ex.getMessage()); return false; } finally { lock.unlock(); } }
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); } }
socket.setKeepAlive(ENABLE_TCP_KEEP_ALIVE); socket.setReceiveBufferSize(socketBufferSize); socket.setKeepAlive(ENABLE_TCP_KEEP_ALIVE); socket.setReceiveBufferSize(socketBufferSize);
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); } } }
public static BioSocketChannel open(SocketAddress address) throws Exception { Socket socket = new Socket(); socket.setSoTimeout(BioSocketChannel.SO_TIMEOUT); socket.setTcpNoDelay(true); socket.setKeepAlive(true); socket.setReuseAddress(true); socket.connect(address, BioSocketChannel.DEFAULT_CONNECT_TIMEOUT); return new BioSocketChannel(socket); }
socket.setSoTimeout(0); socket.setKeepAlive(true); initialHSStatus = HandshakeStatus.NEED_WRAP; tlsEngine.beginHandshake();
@Override public void run() { try { // the loop eventually terminates when the socket is closed. while (!shuttingDown) { Socket s = serverSocket.accept().socket(); // this prevents a connection from silently terminated by the router in between or the other peer // and that goes without unnoticed. However, the time out is often very long (for example 2 hours // by default in Linux) that this alone is enough to prevent that. s.setKeepAlive(true); // we take care of buffering on our own s.setTcpNoDelay(true); new ConnectionHandler(s, new ConnectionHandlerFailureCallback(this) { @Override public void run(Throwable cause) { LOGGER.log(Level.WARNING, "Connection handler failed, restarting listener", cause); shutdown(); TcpSlaveAgentListenerRescheduler.schedule(getParentThread(), cause); } }).start(); } } catch (IOException e) { if(!shuttingDown) { LOGGER.log(Level.SEVERE,"Failed to accept TCP connections", e); } } }
private TNonblockingSocket(SocketChannel socketChannel, int timeout, SocketAddress socketAddress) throws IOException { socketChannel_ = socketChannel; socketAddress_ = socketAddress; // make it a nonblocking channel socketChannel.configureBlocking(false); // set options Socket socket = socketChannel.socket(); socket.setSoLinger(false, 0); socket.setTcpNoDelay(true); socket.setKeepAlive(true); setTimeout(timeout); }
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);
@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); } } },
/** * */ public Socket create(String host, int port) throws Exception { final Socket r = new Socket(host, port); r.setKeepAlive(this.keepAlive); r.setTcpNoDelay(this.tcpNoDelay); if(this.receiveBufferSize > 0) r.setReceiveBufferSize(this.receiveBufferSize); return r; }
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); } } }