public boolean finishConnect() throws IOException { return socketChannel.finishConnect(); }
@Override public boolean finishConnect() throws IOException { boolean connected = socketChannel.finishConnect(); if (connected) key.interestOps(key.interestOps() & ~SelectionKey.OP_CONNECT | SelectionKey.OP_READ); return connected; }
/** * does socketChannel.finishConnect() */ @Override public boolean finishConnect() throws IOException { boolean connected = socketChannel.finishConnect(); if (connected) key.interestOps(key.interestOps() & ~SelectionKey.OP_CONNECT | SelectionKey.OP_READ); return connected; }
@Override protected void doFinishConnect() throws Exception { if (!javaChannel().finishConnect()) { throw new Error(); } }
@Override protected void doFinishConnect() throws Exception { if (!javaChannel().finishConnect()) { throw new Error(); } }
public boolean finishConnect() throws IOException { if (channel.isConnectionPending()) { channel.finishConnect(); localPort = channel.socket().getLocalPort(); isFinishConnect = true; return true; } else { return false; } }
@Override protected void doFinishConnect() throws Exception { if (!javaChannel().finishConnect()) { throw new Error(); } }
/** * This will connect the channel; if it is in a pending state then this will finish * establishing the connection. Finally the socket handler is registered with this * channel. * * @throws IOException if anything goes wrong during the connection establishment * or registering of the handler */ private void connect(SelectionKey selectionKey) throws IOException { SocketChannel clientChannel = (SocketChannel) selectionKey.channel(); if (clientChannel.isConnectionPending()) { clientChannel.finishConnect(); } clientChannel.register(AbstractSocketHandler.this.selector, SelectionKey.OP_READ); }
private void connect() throws IOException { if (this.proxy.isOpen()) { if (this.proxy.finishConnect()) { this.proxy.register(this.selector, SelectionKey.OP_WRITE, this); SelectionKey clientKey = this.client.keyFor(this.selector); if (clientKey != null) { clientKey.cancel(); } this.state = HandlerState.WRITING; } else if (this.connectStartTime + Config.PROXY_CONNECT_TIMEOUT_MS < System.currentTimeMillis()) { LOG.warn("Proxy connect timed out for client {}", this.client); closeChannels(); } } }
@Override public void connect(SelectionKey key) { try { channel.socketChannel().finishConnect(); key.attach(channel); } catch (IOException e) { eventHandler().exceptionCaught(channel, e); key.cancel(); return; } key.interestOps(SelectionKey.OP_READ); }
@Override public void connect(SelectionKey key) { try { channel.socketChannel().finishConnect(); key.attach(channel); } catch (IOException e) { eventHandler().exceptionCaught(channel, e); key.cancel(); return; } key.interestOps(SelectionKey.OP_READ); }
@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); }
@Override public void run() { if (key != null && key.isValid()) { SocketChannel channel = (SocketChannel) key.channel(); Beat beat = (Beat) key.attachment(); if (channel.isConnected()) { return; } try { channel.finishConnect(); } catch (Exception ignore) { } try { beat.finishCheck(false, false, beat.getTask().getCheckRTNormalized() * 2, "tcp:timeout"); key.cancel(); key.channel().close(); } catch (Exception ignore) { } } } }
private static void connect(SelectionKey k) throws IOException { NioClientSocketChannel ch = (NioClientSocketChannel) k.attachment(); try { if (ch.channel.finishConnect()) { k.cancel(); if (ch.timoutTimer != null) { ch.timoutTimer.cancel(); } ch.worker.register(ch, ch.connectFuture); } } catch (ConnectException e) { ConnectException newE = new ConnectException(e.getMessage() + ": " + ch.requestedRemoteAddress); newE.setStackTrace(e.getStackTrace()); throw newE; } }
channel.finishConnect(); beat.finishCheck(true, false, System.currentTimeMillis() - beat.getTask().getStartTime(), "tcp:ok+");
@Override protected void connectOP(SelectionKey key) throws IOException { U.must(key.isConnectable()); SocketChannel socketChannel = (SocketChannel) key.channel(); if (!socketChannel.isConnectionPending()) { // not ready to retrieve the connection status return; } ConnectionTarget target = (ConnectionTarget) key.attachment(); boolean ready; try { ready = socketChannel.finishConnect(); U.must(ready, "Expected an established connection!"); Log.info("Connected", "address", target.addr); connected.add(new RapidoidChannel(socketChannel, true, target.protocol, target.holder, target.reconnecting, target.state)); } catch (ConnectException e) { retryConnecting(target); } }
private void connectionEstablished(SelectionKey key, Object att) throws Exception { SocketChannel channel = (SocketChannel) key.channel(); if (!channel.isConnectionPending()) return; Attachment attachment = (Attachment) att; AsyncConnection conn; try { channel.finishConnect(); nioEventLoopAdapter.addSocketChannel(channel); NioWritableChannel writableChannel = new NioWritableChannel(channel, this); if (attachment.connectionManager != null) { conn = attachment.connectionManager.createConnection(writableChannel, false); } else { conn = new TcpClientConnection(writableChannel, this); } conn.setInetSocketAddress(attachment.inetSocketAddress); addConnection(attachment.inetSocketAddress, conn); channel.register(nioEventLoopAdapter.getSelector(), SelectionKey.OP_READ, conn); } finally { attachment.latch.countDown(); } }
SocketChannel sc = ((SocketChannel) k.channel()); if ((k.readyOps() & SelectionKey.OP_CONNECT) != 0) { if (sc.finishConnect()) { updateLastSendAndHeard(); updateSocketAddresses();
protected void connect(Address dest, boolean send_local_addr) throws Exception { SocketAddress destAddr=new InetSocketAddress(((IpAddress)dest).getIpAddress(), ((IpAddress)dest).getPort()); try { if(!server.deferClientBinding()) this.channel.bind(new InetSocketAddress(server.clientBindAddress(), server.clientBindPort())); this.key=server.register(channel, SelectionKey.OP_CONNECT | SelectionKey.OP_READ, this); if(Util.connect(channel, destAddr) && channel.finishConnect()) { clearSelectionKey(SelectionKey.OP_CONNECT); this.connected=channel.isConnected(); } if(this.channel.getLocalAddress() != null && this.channel.getLocalAddress().equals(destAddr)) throw new IllegalStateException("socket's bind and connect address are the same: " + destAddr); if(send_local_addr) sendLocalAddress(server.localAddress()); } catch(Exception t) { close(); throw t; } }
void handleReady(final int ops) { final SocketChannel channel = getChannel(); boolean ok = false; try { if (channel.finishConnect()) { selectorLog.tracef("handleReady connect finished"); suspend(SelectionKey.OP_CONNECT); getSelectionKey().attach(connection.getConduit()); if (futureResult.setResult(connection)) { ok = true; ChannelListeners.invokeChannelListener(connection, openListener); } } } catch (IOException e) { selectorLog.tracef("ConnectHandle.handleReady Exception, " + e); futureResult.setException(e); } finally { if (!ok) { selectorLog.tracef("!OK, closing connection"); safeClose(connection); } } }