public InetSocketAddress getLocalAddress() { InetSocketAddress localAddress = this.localAddress; if (localAddress == null) { try { localAddress = getLocalSocketAddress(); if (localAddress.getAddress().isAnyLocalAddress()) { // Don't cache on a wildcard address so the correct one // will be cached once the channel is connected/bound return localAddress; } this.localAddress = localAddress; } catch (Throwable t) { // Sometimes fails on a closed socket in Windows. return null; } } return localAddress; }
public InetSocketAddress getRemoteAddress() { InetSocketAddress remoteAddress = this.remoteAddress; if (remoteAddress == null) { try { this.remoteAddress = remoteAddress = getRemoteSocketAddress(); } catch (Throwable t) { // Sometimes fails on a closed socket in Windows. return null; } } return remoteAddress; }
@Override protected boolean setClosed() { if (super.setClosed()) { state = ST_CLOSED; return true; } return false; }
protected void setOpWrite(AbstractNioChannel<?> channel) { Selector selector = this.selector; SelectionKey key = channel.channel.keyFor(selector); if (key == null) { return; } if (!key.isValid()) { close(key); return; } int interestOps = channel.getInternalInterestOps(); if ((interestOps & SelectionKey.OP_WRITE) == 0) { interestOps |= SelectionKey.OP_WRITE; key.interestOps(interestOps); channel.setInternalInterestOps(interestOps); } }
protected void close(AbstractNioChannel<?> channel, ChannelFuture future) { boolean connected = channel.isConnected(); boolean bound = channel.isBound(); boolean iothread = isIoThread(channel); increaseCancelledKeys(); if (channel.setClosed()) { future.setSuccess(); if (connected) {
final WritableByteChannel ch = channel.channel; final WriteRequestQueue writeBuffer = channel.writeBufferQueue; final int writeSpinCount = channel.getConfig().getWriteSpinCount(); List<Throwable> causes = null;
void setInterestOps(final AbstractNioChannel<?> channel, final ChannelFuture future, final int interestOps) { boolean iothread = isIoThread(channel); if (!iothread) { channel.getPipeline().execute(new Runnable() { public void run() { setInterestOps(channel, future, interestOps); int newInterestOps = interestOps & ~Channel.OP_WRITE | channel.getInternalInterestOps() & Channel.OP_WRITE; if (channel.getInternalInterestOps() != newInterestOps) { changed = true; channel.setInternalInterestOps(newInterestOps); if (channel.getInternalInterestOps() != newInterestOps) { changed = true; key.interestOps(newInterestOps); selector.wakeup(); channel.setInternalInterestOps(newInterestOps);
@Override public int getInterestOps() { if (!isOpen()) { return Channel.OP_WRITE; } int interestOps = getRawInterestOps(); int writeBufferSize = this.writeBufferSize.get(); if (writeBufferSize != 0) { if (highWaterMarkCounter.get() > 0) { int lowWaterMark = getConfig().getWriteBufferLowWaterMark(); if (writeBufferSize >= lowWaterMark) { interestOps |= Channel.OP_WRITE; } else { interestOps &= ~Channel.OP_WRITE; } } else { int highWaterMark = getConfig().getWriteBufferHighWaterMark(); if (writeBufferSize >= highWaterMark) { interestOps |= Channel.OP_WRITE; } else { interestOps &= ~Channel.OP_WRITE; } } } else { interestOps &= ~Channel.OP_WRITE; } return interestOps; }
@Override public void writeFromUserCode(final AbstractNioChannel<?> channel) { /* * Note that we are not checking if the channel is connected. Connected * has a different meaning in UDP and means that the channels socket is * configured to only send and receive from a given remote peer. */ if (!channel.isBound()) { cleanUpWriteBuffer(channel); return; } if (scheduleWriteIfNecessary(channel)) { return; } // From here, we are sure Thread.currentThread() == workerThread. if (channel.writeSuspended) { return; } if (channel.inWriteNowLoop) { return; } write0(channel); }
public void setInterestOps(final AbstractNioChannel<?> channel, final ChannelFuture future, final int interestOps) { boolean iothread = isIoThread(channel); if (!iothread) { channel.getPipeline().execute(new Runnable() { public void run() { setInterestOps(channel, future, interestOps); int newInterestOps = interestOps & ~Channel.OP_WRITE | channel.getRawInterestOps() & Channel.OP_WRITE; if (channel.getRawInterestOps() != newInterestOps) { changed = true; channel.setRawInterestOpsNow(newInterestOps); if (channel.getRawInterestOps() != newInterestOps) { changed = true; key.interestOps(newInterestOps); selector.wakeup(); channel.setRawInterestOpsNow(newInterestOps);
protected void clearOpWrite(AbstractNioChannel<?> channel) { Selector selector = this.selector; SelectionKey key = channel.channel.keyFor(selector); if (key == null) { return; } if (!key.isValid()) { close(key); return; } int interestOps = channel.getRawInterestOps(); if ((interestOps & SelectionKey.OP_WRITE) != 0) { interestOps &= ~SelectionKey.OP_WRITE; key.interestOps(interestOps); channel.setRawInterestOpsNow(interestOps); } }
@Override public NioDatagramWorker getWorker() { return (NioDatagramWorker) super.getWorker(); }
public void close(AbstractNioChannel<?> channel, ChannelFuture future) { boolean connected = channel.isConnected(); boolean bound = channel.isBound(); boolean iothread = isIoThread(channel); increaseCancelledKeys(); if (channel.setClosed()) { future.setSuccess(); if (connected) {
@Override public ChannelFuture write(Object message, SocketAddress remoteAddress) { if (remoteAddress == null || remoteAddress.equals(getRemoteAddress())) { return super.write(message, null); } else { return getUnsupportedOperationFuture(); } } }
final DatagramChannel ch = ((NioDatagramChannel) channel).getDatagramChannel(); final WriteRequestQueue writeBuffer = channel.writeBufferQueue; final int writeSpinCount = channel.getConfig().getWriteSpinCount(); synchronized (channel.writeLock) {
@Override public void writeFromUserCode(final AbstractNioChannel<?> channel) { /* * Note that we are not checking if the channel is connected. Connected * has a different meaning in UDP and means that the channels socket is * configured to only send and receive from a given remote peer. */ if (!channel.isBound()) { cleanUpWriteBuffer(channel); return; } if (scheduleWriteIfNecessary(channel)) { return; } // From here, we are sure Thread.currentThread() == workerThread. if (channel.writeSuspended) { return; } if (channel.inWriteNowLoop) { return; } write0(channel); }
protected void clearOpWrite(AbstractNioChannel<?> channel) { Selector selector = this.selector; SelectionKey key = channel.channel.keyFor(selector); if (key == null) { return; } if (!key.isValid()) { close(key); return; } int interestOps = channel.getInternalInterestOps(); if ((interestOps & SelectionKey.OP_WRITE) != 0) { interestOps &= ~SelectionKey.OP_WRITE; key.interestOps(interestOps); channel.setInternalInterestOps(interestOps); } }
protected void setOpWrite(AbstractNioChannel<?> channel) { Selector selector = this.selector; SelectionKey key = channel.channel.keyFor(selector); if (key == null) { return; } if (!key.isValid()) { close(key); return; } int interestOps = channel.getRawInterestOps(); if ((interestOps & SelectionKey.OP_WRITE) == 0) { interestOps |= SelectionKey.OP_WRITE; key.interestOps(interestOps); channel.setRawInterestOpsNow(interestOps); } }
@Override public NioWorker getWorker() { return (NioWorker) super.getWorker(); }