/** * Returns an off-heap copy of the specified {@link ByteBuf}, and releases the specified holder. * The caller must ensure that the holder releases the original {@link ByteBuf} when the holder is released by * this method. */ protected final ByteBuf newDirectBuffer(Object holder, ByteBuf buf) { final int readableBytes = buf.readableBytes(); if (readableBytes == 0) { ReferenceCountUtil.release(holder); return Unpooled.EMPTY_BUFFER; } final ByteBufAllocator alloc = alloc(); if (alloc.isDirectBufferPooled()) { return newDirectBuffer0(holder, buf, alloc, readableBytes); } final ByteBuf directBuf = ByteBufUtil.threadLocalDirectBuffer(); if (directBuf == null) { return newDirectBuffer0(holder, buf, alloc, readableBytes); } directBuf.writeBytes(buf, buf.readerIndex(), readableBytes); ReferenceCountUtil.safeRelease(holder); return directBuf; }
checkResolvable((InetSocketAddress) localAddress); ? (InetSocketAddress) remoteAddress : null; if (remoteSocketAddr != null) { checkResolvable(remoteSocketAddr); boolean connected = doConnect0(remoteAddress); if (connected) { remote = remoteSocketAddr == null ?
@Override protected final void autoReadCleared() { ((AbstractKQueueChannel) channel).clearReadFilter(); }
@Override protected final void doBeginRead() throws Exception { // Channel.read() or ChannelHandlerContext.read() was called final AbstractKQueueUnsafe unsafe = (AbstractKQueueUnsafe) unsafe(); unsafe.readPending = true; // We must set the read flag here as it is possible the user didn't read in the last read loop, the // executeReadReadyRunnable could read nothing, and if the user doesn't explicitly call read they will // never get data after this. readFilter(true); // If auto read was toggled off on the last read loop then we may not be notified // again if we didn't consume all the data. So we force a read operation here if there maybe more data. if (unsafe.maybeMoreDataToRead) { unsafe.executeReadReadyRunnable(config()); } }
@Override public void run() { try { doDeregister(); } catch (Throwable cause) { pipeline().fireExceptionCaught(cause); } } });
private boolean doConnect0(SocketAddress remote) throws Exception { boolean success = false; try { boolean connected = socket.connect(remote); if (!connected) { writeFilter(true); } success = true; return connected; } finally { if (!success) { doClose(); } } }
boolean wasActive = isActive(); if (doConnect(remoteAddress, localAddress)) { fulfillConnectPromise(promise, wasActive); } else { int connectTimeoutMillis = config().getConnectTimeoutMillis(); if (connectTimeoutMillis > 0) { connectTimeoutFuture = eventLoop().schedule(new Runnable() { @Override public void run() {
if (isRegistered()) { EventLoop loop = eventLoop(); if (loop.inEventLoop()) { doDeregister(); } else { loop.execute(new Runnable() {
void readFilter(boolean readFilterEnabled) throws IOException { if (this.readFilterEnabled != readFilterEnabled) { this.readFilterEnabled = readFilterEnabled; evSet(Native.EVFILT_READ, readFilterEnabled ? Native.EV_ADD_CLEAR_ENABLE : Native.EV_DELETE_DISABLE); } }
@Override protected void doClose() throws Exception { super.doClose(); connected = false; }
@Override protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception { if (super.doConnect(remoteAddress, localAddress)) { connected = true; return true; } return false; }
@Override public void run() { if (!unsafe.readPending && !config().isAutoRead()) { // Still no read triggered so clear it now unsafe.clearReadFilter0(); } } });
@Override protected void doBind(SocketAddress localAddress) throws Exception { super.doBind(localAddress); active = true; }
@Override protected void doBind(SocketAddress local) throws Exception { if (local instanceof InetSocketAddress) { checkResolvable((InetSocketAddress) local); } socket.bind(local); this.local = socket.localAddress(); }
boolean wasActive = isActive(); if (doConnect(remoteAddress, localAddress)) { fulfillConnectPromise(promise, wasActive); } else { int connectTimeoutMillis = config().getConnectTimeoutMillis(); if (connectTimeoutMillis > 0) { connectTimeoutFuture = eventLoop().schedule(new Runnable() { @Override public void run() {
@Override protected final void doBeginRead() throws Exception { // Channel.read() or ChannelHandlerContext.read() was called final AbstractKQueueUnsafe unsafe = (AbstractKQueueUnsafe) unsafe(); unsafe.readPending = true; // We must set the read flag here as it is possible the user didn't read in the last read loop, the // executeReadReadyRunnable could read nothing, and if the user doesn't explicitly call read they will // never get data after this. readFilter(true); // If auto read was toggled off on the last read loop then we may not be notified // again if we didn't consume all the data. So we force a read operation here if there maybe more data. if (unsafe.maybeMoreDataToRead) { unsafe.executeReadReadyRunnable(config()); } }
if (isRegistered()) { EventLoop loop = eventLoop(); if (loop.inEventLoop()) { doDeregister(); } else { loop.execute(new Runnable() {
@Override public void run() { try { doDeregister(); } catch (Throwable cause) { pipeline().fireExceptionCaught(cause); } } });
private boolean doConnect0(SocketAddress remote) throws Exception { boolean success = false; try { boolean connected = socket.connect(remote); if (!connected) { writeFilter(true); } success = true; return connected; } finally { if (!success) { doClose(); } } }