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); }
@Override public InetSocketAddress getRemoteSocketAddress() { if (sock.isOpen() == false) { return null; } return (InetSocketAddress) sock.socket().getRemoteSocketAddress(); }
/** * create a socket channel. * @return the created socket channel * @throws IOException */ SocketChannel createSock() throws IOException { SocketChannel sock; sock = SocketChannel.open(); sock.configureBlocking(false); sock.socket().setSoLinger(false, -1); sock.socket().setTcpNoDelay(true); return sock; }
public HAConnection(final HAService haService, final SocketChannel socketChannel) throws IOException { this.haService = haService; this.socketChannel = socketChannel; this.clientAddr = this.socketChannel.socket().getRemoteSocketAddress().toString(); this.socketChannel.configureBlocking(false); this.socketChannel.socket().setSoLinger(false, -1); this.socketChannel.socket().setTcpNoDelay(true); this.socketChannel.socket().setReceiveBufferSize(1024 * 64); this.socketChannel.socket().setSendBufferSize(1024 * 64); this.writeSocketService = new WriteSocketService(this.socketChannel); this.readSocketService = new ReadSocketService(this.socketChannel); this.haService.getConnectionCount().incrementAndGet(); }
public StandardCommsSession(final String hostname, final int port, final int timeoutMillis) throws IOException { socketChannel = SocketChannel.open(); socketChannel.socket().connect(new InetSocketAddress(hostname, port), timeoutMillis); socketChannel.configureBlocking(false); in = new SocketChannelInputStream(socketChannel); bufferedIn = new InterruptableInputStream(new BufferedInputStream(in)); out = new SocketChannelOutputStream(socketChannel); bufferedOut = new InterruptableOutputStream(new BufferedOutputStream(out)); this.hostname = hostname; this.port = port; }
public Handler(@NotNull SocketChannel socket) throws SocketException { this.socket = socket; socket.socket().setSendBufferSize(256 * 1024); socket.socket().setTcpNoDelay(true); }
public Socket createSocket(String type, InetSocketAddress inetSocketAddress) throws IOException { SocketChannel socketChannel = null; Socket socket = null; if (orb.getORBData().connectionSocketType().equals(ORBConstants.SOCKETCHANNEL)) { socketChannel = SocketChannel.open(inetSocketAddress); socket = socketChannel.socket(); } else { socket = new Socket(inetSocketAddress.getHostName(), inetSocketAddress.getPort()); } // Disable Nagle's algorithm (i.e., always send immediately). socket.setTcpNoDelay(true); return socket; }
public NIOServerCnxn(ZooKeeperServer zk, SocketChannel sock, SelectionKey sk, NIOServerCnxnFactory factory, SelectorThread selectorThread) throws IOException { super(zk); this.sock = sock; this.sk = sk; this.factory = factory; this.selectorThread = selectorThread; if (this.factory.login != null) { this.zooKeeperSaslServer = new ZooKeeperSaslServer(factory.login); } sock.socket().setTcpNoDelay(true); /* set socket linger to false, so that socket close does not block */ sock.socket().setSoLinger(false, -1); InetAddress addr = ((InetSocketAddress) sock.socket() .getRemoteSocketAddress()).getAddress(); addAuthInfo(new Id("ip", addr.getHostAddress())); this.sessionTimeout = factory.sessionlessCnxnTimeout; }
ReadWriteHandler(SocketChannel proxy, ByteBuffer mixedServerResponseBuffer, SocketChannel client, Selector selector) throws IOException { this.proxy = proxy; this.client = client; this.selector = selector; // drain response that is not part of proxy's 200 OK and is part of data pushed from server, and push to client if (mixedServerResponseBuffer.limit() > mixedServerResponseBuffer.position()) { this.client.configureBlocking(true); OutputStream clientOut = this.client.socket().getOutputStream(); clientOut.write(mixedServerResponseBuffer.array(), mixedServerResponseBuffer.position(), mixedServerResponseBuffer.limit() - mixedServerResponseBuffer.position()); clientOut.flush(); } this.proxy.configureBlocking(false); this.client.configureBlocking(false); this.client.register(this.selector, OP_READ, this); this.proxy.register(this.selector, OP_READ, this); }
sc = acceptSocket.accept(); accepted = true; InetAddress ia = sc.socket().getInetAddress(); int cnxncount = getClientCnxnCount(ia); + sc.socket().getRemoteSocketAddress()); sc.configureBlocking(false);
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); }
public static SocketChannel connect(SocketAddress remote, final int timeoutMillis) { SocketChannel sc = null; try { sc = SocketChannel.open(); sc.configureBlocking(true); sc.socket().setSoLinger(false, -1); sc.socket().setTcpNoDelay(true); sc.socket().setReceiveBufferSize(1024 * 64); sc.socket().setSendBufferSize(1024 * 64); sc.socket().connect(remote, timeoutMillis); sc.configureBlocking(false); return sc; } catch (Exception e) { if (sc != null) { try { sc.close(); } catch (IOException e1) { e1.printStackTrace(); } } } return null; }
/** * Used by "dump" 4-letter command to list all connection in * cnxnExpiryMap */ @Override public String toString() { return "ip: " + sock.socket().getRemoteSocketAddress() + " sessionId: 0x" + Long.toHexString(sessionId); }
public SelectionKey accept (Selector selector, SocketChannel socketChannel) throws IOException { writeBuffer.clear(); readBuffer.clear(); readBuffer.flip(); currentObjectLength = 0; try { this.socketChannel = socketChannel; socketChannel.configureBlocking(false); Socket socket = socketChannel.socket(); socket.setTcpNoDelay(true); selectionKey = socketChannel.register(selector, SelectionKey.OP_READ); if (DEBUG) { debug("kryonet", "Port " + socketChannel.socket().getLocalPort() + "/TCP connected to: " + socketChannel.socket().getRemoteSocketAddress()); } lastReadTime = lastWriteTime = System.currentTimeMillis(); return selectionKey; } catch (IOException ex) { close(); throw ex; } }
public SSLCommsSession(final SSLContext sslContext, final String hostname, final int port, final int timeoutMillis) throws IOException { final SocketChannel socketChannel = SocketChannel.open(); socketChannel.socket().connect(new InetSocketAddress(hostname, port), timeoutMillis); socketChannel.configureBlocking(false); sslSocketChannel = new SSLSocketChannel(sslContext, socketChannel,true); in = new SSLSocketChannelInputStream(sslSocketChannel); bufferedIn = new BufferedInputStream(in); out = new SSLSocketChannelOutputStream(sslSocketChannel); bufferedOut = new BufferedOutputStream(out); this.sslContext = sslContext; this.hostname = hostname; this.port = port; }
public SocketTransceiver(SocketChannel channel) throws IOException { this.channel = channel; this.channel.socket().setTcpNoDelay(true); LOG.info("open to "+getRemoteName()); }
/** Create using the specified {@link SaslClient}. */ public SaslSocketTransceiver(SocketAddress address, SaslClient saslClient) throws IOException { this.sasl = new SaslParticipant(saslClient); this.channel = SocketChannel.open(address); this.channel.socket().setTcpNoDelay(true); LOG.debug("open to {}", getRemoteName()); open(true); }
public NIOServerCnxn(ZooKeeperServer zk, SocketChannel sock, SelectionKey sk, NIOServerCnxnFactory factory) throws IOException { this.zkServer = zk; this.sock = sock; this.sk = sk; this.factory = factory; if (this.factory.login != null) { this.zooKeeperSaslServer = new ZooKeeperSaslServer(factory.login); } if (zk != null) { outstandingLimit = zk.getGlobalOutstandingLimit(); } sock.socket().setTcpNoDelay(true); /* set socket linger to false, so that socket close does not * block */ sock.socket().setSoLinger(false, -1); InetAddress addr = ((InetSocketAddress) sock.socket() .getRemoteSocketAddress()).getAddress(); authInfo.add(new Id("ip", addr.getHostAddress())); sk.interestOps(SelectionKey.OP_READ); }