@Override protected DatagramChannel open(SocketAddress localAddress) throws Exception { final DatagramChannel c = DatagramChannel.open(); boolean success = false; try { new NioDatagramSessionConfig(c).setAll(getSessionConfig()); c.configureBlocking(false); c.socket().bind(localAddress); c.register(selector, SelectionKey.OP_READ); success = true; } finally { if (!success) { close(c); } } return c; }
/** * Creates a new acceptor-side session instance. */ NioDatagramSession(IoService service, DatagramChannel ch, IoProcessor<NioSession> processor, SocketAddress remoteAddress) { this.service = service; this.ch = ch; this.config = new NioDatagramSessionConfig(ch); this.handler = service.getHandler(); this.processor = processor; this.remoteAddress = (InetSocketAddress) remoteAddress; this.localAddress = (InetSocketAddress) ch.socket().getLocalSocketAddress(); }
/** * Creates a new acceptor-side session instance. */ NioDatagramSession(IoService service, DatagramChannel channel, IoProcessor<NioSession> processor, SocketAddress remoteAddress) { super(processor, service, channel); config = new NioDatagramSessionConfig(channel); config.setAll(service.getSessionConfig()); this.remoteAddress = (InetSocketAddress) remoteAddress; this.localAddress = (InetSocketAddress) channel.socket().getLocalSocketAddress(); }
protected DatagramChannel open(SocketAddress localAddress) throws Exception { final DatagramChannel ch = DatagramChannel.open(); boolean success = false; try { new NioDatagramSessionConfig(ch).setAll(getSessionConfig()); ch.configureBlocking(false); try { ch.socket().bind(localAddress); } catch (IOException ioe) { // Add some info regarding the address we try to bind to the // message String newMessage = "Error while binding on " + localAddress + "\n" + "original message : " + ioe.getMessage(); Exception e = new IOException(newMessage); e.initCause(ioe.getCause()); // And close the channel ch.close(); throw e; } ch.register(selector, SelectionKey.OP_READ); success = true; } finally { if (!success) { close(ch); } } return ch; }
/** * Creates a new acceptor-side session instance. */ NioDatagramSession(IoService service, DatagramChannel channel, IoProcessor<NioSession> processor, SocketAddress remoteAddress) { super(processor, service, channel); config = new NioDatagramSessionConfig(channel); config.setAll(service.getSessionConfig()); this.remoteAddress = (InetSocketAddress) remoteAddress; this.localAddress = (InetSocketAddress) channel.socket().getLocalSocketAddress(); }
protected DatagramChannel open(SocketAddress localAddress) throws Exception { final DatagramChannel ch = DatagramChannel.open(); boolean success = false; try { new NioDatagramSessionConfig(ch).setAll(getSessionConfig()); ch.configureBlocking(false); try { ch.socket().bind(localAddress); } catch (IOException ioe) { // Add some info regarding the address we try to bind to the // message String newMessage = "Error while binding on " + localAddress + "\n" + "original message : " + ioe.getMessage(); Exception e = new IOException(newMessage); e.initCause(ioe.getCause()); // And close the channel ch.close(); throw e; } ch.register(selector, SelectionKey.OP_READ); success = true; } finally { if (!success) { close(ch); } } return ch; }