@Override protected void handleAccept(SelectionKey key) throws Exception { SocketChannel client_channel=channel.accept(); NioConnection conn=null; if(client_channel == null) return; // can happen if no connection is available to accept try { conn=new NioConnection(client_channel, NioServer.this); SelectionKey client_key=client_channel.register(selector, SelectionKey.OP_READ, conn); conn.key(client_key); // we need to set the selection key of the client channel *not* the server channel Address peer_addr=conn.peerAddress(); if(use_peer_connections) return; synchronized(this) { replaceConnection(peer_addr, conn); // closes old conn conn.start(); log.trace("%s: accepted connection from %s", local_addr, peer_addr); } } catch(Throwable ex) { Util.close(conn); removeConnectionIfPresent(conn.peerAddress(), conn); throw ex; } }
@Override protected void handleAccept(SelectionKey key) throws Exception { SocketChannel client_channel=channel.accept(); NioConnection conn=null; if(client_channel == null) return; // can happen if no connection is available to accept try { conn=new NioConnection(client_channel, NioServer.this); SelectionKey client_key=client_channel.register(selector, SelectionKey.OP_READ, conn); conn.key(client_key); // we need to set the selection key of the client channel *not* the server channel Address peer_addr=conn.peerAddress(); if(use_peer_connections) return; synchronized(this) { replaceConnection(peer_addr, conn); // closes old conn conn.start(); log.trace("%s: accepted connection from %s", local_addr, peer_addr); } } catch(Throwable ex) { Util.close(conn); removeConnectionIfPresent(conn.peerAddress(), conn); throw ex; } }