public void close() throws IOException { if (!callFlag.getAndSet(true)) { udpServerChannelLog.tracef("Closing %s", this); try { cancelKeys(); } catch (Throwable ignored) {} try { datagramChannel.close(); } finally { invokeCloseHandler(); } } }
@Deprecated public XnioExecutor getWriteThread() { return getIoThread(); }
public <A extends SocketAddress> A getLocalAddress(final Class<A> type) { return type.isInstance(getLocalAddress()) ? type.cast(getLocalAddress()) : null; }
void handleReady(int ops) { try { if (ops == 0) { // the dreaded bug final SelectionKey key = getSelectionKey(); final int interestOps = key.interestOps(); if (interestOps != 0) { ops = interestOps; } else { // urp forceTermination(); return; } } if (Bits.allAreSet(ops, SelectionKey.OP_READ)) try { ChannelListeners.invokeChannelListener(channel, channel.getReadListener()); } catch (Throwable ignored) { } if (Bits.allAreSet(ops, SelectionKey.OP_WRITE)) try { ChannelListeners.invokeChannelListener(channel, channel.getWriteListener()); } catch (Throwable ignored) { } } catch (CancelledKeyException ignored) {} }
public long receiveFrom(final SocketAddressBuffer addressBuffer, final ByteBuffer[] buffers) throws IOException { return receiveFrom(addressBuffer, buffers, 0, buffers.length); }
public boolean sendTo(final SocketAddress target, final ByteBuffer[] buffers) throws IOException { return sendTo(target, buffers, 0, buffers.length); }
void terminated() { channel.invokeCloseHandler(); } }
/** {@inheritDoc} */ public MulticastMessageChannel createUdpServer(final InetSocketAddress bindAddress, final ChannelListener<? super MulticastMessageChannel> bindListener, final OptionMap optionMap) throws IOException { checkShutdown(); final DatagramChannel channel; if (bindAddress != null) { InetAddress address = bindAddress.getAddress(); if (address instanceof Inet6Address) { channel = DatagramChannel.open(StandardProtocolFamily.INET6); } else { channel = DatagramChannel.open(StandardProtocolFamily.INET); } } else { channel = DatagramChannel.open(); } channel.configureBlocking(false); if (optionMap.contains(Options.BROADCAST)) channel.socket().setBroadcast(optionMap.get(Options.BROADCAST, false)); if (optionMap.contains(Options.IP_TRAFFIC_CLASS)) channel.socket().setTrafficClass(optionMap.get(Options.IP_TRAFFIC_CLASS, -1)); if (optionMap.contains(Options.RECEIVE_BUFFER)) channel.socket().setReceiveBufferSize(optionMap.get(Options.RECEIVE_BUFFER, -1)); channel.socket().setReuseAddress(optionMap.get(Options.REUSE_ADDRESSES, true)); if (optionMap.contains(Options.SEND_BUFFER)) channel.socket().setSendBufferSize(optionMap.get(Options.SEND_BUFFER, -1)); channel.socket().bind(bindAddress); final NioUdpChannel udpChannel = new NioUdpChannel(this, channel); ChannelListeners.invokeChannelListener(udpChannel, bindListener); return udpChannel; }
void handleReady(int ops) { try { if (ops == 0) { // the dreaded bug final SelectionKey key = getSelectionKey(); final int interestOps = key.interestOps(); if (interestOps != 0) { ops = interestOps; } else { // urp forceTermination(); return; } } if (Bits.allAreSet(ops, SelectionKey.OP_READ)) try { ChannelListeners.invokeChannelListener(channel, channel.getReadListener()); } catch (Throwable ignored) { } if (Bits.allAreSet(ops, SelectionKey.OP_WRITE)) try { ChannelListeners.invokeChannelListener(channel, channel.getWriteListener()); } catch (Throwable ignored) { } } catch (CancelledKeyException ignored) {} }
public long receiveFrom(final SocketAddressBuffer addressBuffer, final ByteBuffer[] buffers, final int offs, final int len) throws IOException { if (len == 0) { return 0L; } if (len == 1) { return receiveFrom(addressBuffer, buffers[offs]); } final int o = (int) Math.min(Buffers.remaining(buffers, offs, len), 65536L); final ByteBuffer buffer = ByteBuffer.allocate(o); final SocketAddress sourceAddress; try { sourceAddress = datagramChannel.receive(buffer); } catch (ClosedChannelException e) { return -1L; } if (sourceAddress == null) { return 0L; } else { final int t = o - buffer.remaining(); buffer.flip(); Buffers.copy(buffers, offs, len, buffer); if (addressBuffer != null) { addressBuffer.setSourceAddress(sourceAddress); addressBuffer.setDestinationAddress(null); } return t; } }
public boolean sendTo(final SocketAddress target, final ByteBuffer[] buffers, final int offset, final int length) throws IOException { if (length == 0) { return false; } if (length == 1) { return sendTo(target, buffers[offset]); } final long o = Buffers.remaining(buffers, offset, length); if (o > 65535L) { // there will never be enough room throw log.bufferTooLarge(); } final ByteBuffer buffer = ByteBuffer.allocate((int) o); Buffers.copy(buffer, buffers, offset, length); buffer.flip(); return datagramChannel.send(buffer, target) != 0; }
void terminated() { channel.invokeCloseHandler(); } }
/** {@inheritDoc} */ public MulticastMessageChannel createUdpServer(final InetSocketAddress bindAddress, final ChannelListener<? super MulticastMessageChannel> bindListener, final OptionMap optionMap) throws IOException { checkShutdown(); final DatagramChannel channel; if (bindAddress != null) { InetAddress address = bindAddress.getAddress(); if (address instanceof Inet6Address) { channel = DatagramChannel.open(StandardProtocolFamily.INET6); } else { channel = DatagramChannel.open(StandardProtocolFamily.INET); } } else { channel = DatagramChannel.open(); } channel.configureBlocking(false); if (optionMap.contains(Options.BROADCAST)) channel.socket().setBroadcast(optionMap.get(Options.BROADCAST, false)); if (optionMap.contains(Options.IP_TRAFFIC_CLASS)) channel.socket().setTrafficClass(optionMap.get(Options.IP_TRAFFIC_CLASS, -1)); if (optionMap.contains(Options.RECEIVE_BUFFER)) channel.socket().setReceiveBufferSize(optionMap.get(Options.RECEIVE_BUFFER, -1)); channel.socket().setReuseAddress(optionMap.get(Options.REUSE_ADDRESSES, true)); if (optionMap.contains(Options.SEND_BUFFER)) channel.socket().setSendBufferSize(optionMap.get(Options.SEND_BUFFER, -1)); channel.socket().bind(bindAddress); final NioUdpChannel udpChannel = new NioUdpChannel(this, channel); ChannelListeners.invokeChannelListener(udpChannel, bindListener); return udpChannel; }
public void close() throws IOException { if (!callFlag.getAndSet(true)) { udpServerChannelLog.tracef("Closing %s", this); try { cancelKeys(); } catch (Throwable ignored) {} try { datagramChannel.close(); } finally { invokeCloseHandler(); } } }
void handleReady(int ops) { try { if (ops == 0) { // the dreaded bug final SelectionKey key = getSelectionKey(); final int interestOps = key.interestOps(); if (interestOps != 0) { ops = interestOps; } else { // urp forceTermination(); return; } } if (Bits.allAreSet(ops, SelectionKey.OP_READ)) try { ChannelListeners.invokeChannelListener(channel, channel.getReadListener()); } catch (Throwable ignored) { } if (Bits.allAreSet(ops, SelectionKey.OP_WRITE)) try { ChannelListeners.invokeChannelListener(channel, channel.getWriteListener()); } catch (Throwable ignored) { } } catch (CancelledKeyException ignored) {} }
@Deprecated public XnioExecutor getReadThread() { return getIoThread(); }
public long receiveFrom(final SocketAddressBuffer addressBuffer, final ByteBuffer[] buffers) throws IOException { return receiveFrom(addressBuffer, buffers, 0, buffers.length); }
public boolean sendTo(final SocketAddress target, final ByteBuffer[] buffers) throws IOException { return sendTo(target, buffers, 0, buffers.length); }
void terminated() { channel.invokeCloseHandler(); } }
public <A extends SocketAddress> A getLocalAddress(final Class<A> type) { return type.isInstance(getLocalAddress()) ? type.cast(getLocalAddress()) : null; }