private boolean write() throws IOException { boolean processed = false; int interest = _key.interestOps(); int pending = _transport.pending(); if (pending >= 0) { int wrote = _channel.write(_transport.head()); if (wrote > 0) { processed = true; _transport.pop(wrote); } } else { _outputDone = true; } pending = _transport.pending(); if (pending > 0) { interest |= SelectionKey.OP_WRITE; } else { interest &= ~SelectionKey.OP_WRITE; if (pending < 0) { _outputDone = true; } } _key.interestOps(interest); return processed; }
@Override public ByteBuf outputBuffer() { synchronized (lock) { int pending = transport.pending(); if (pending < 0) { return null;//throw new IllegalStateException("xxx need to close the connection"); } int size = pending - offset; if (size < 0) { throw new IllegalStateException("negative size: " + pending); } if (size == 0) { return null; } // For returning PooledBytes ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(size); ByteBuffer head = transport.head(); head.position(offset); head.limit(offset + size); buffer.writeBytes(head); offset += size; // incrementing offset for future calls return buffer; } }
private void writeToNetwork(Connection connection, OutputStream out) throws IOException { Transport transport = connection.getTransport(); while(transport.pending() > 0) { ByteBuffer outputBuf = transport.head(); final int size = outputBuf.remaining(); byte[] tmpBuf = new byte[size]; outputBuf.get(tmpBuf); LOG.tracev("writing {0} bytes", size); out.write(tmpBuf); transport.pop(size); } }
private static int pending(Selectable selectable) { Transport transport = ((SelectableImpl)selectable).getTransport(); int pending = transport.pending(); if (pending < 0) { if (transport.isClosed()) { selectable.terminate(); } } return pending; }
private static int pending(Selectable selectable) { Transport transport = ((SelectableImpl)selectable).getTransport(); int pending = transport.pending(); if (pending < 0) { if (transport.isClosed()) { selectable.terminate(); } } return pending; }
transport.close_tail(); transport.close_head(); transport.pop(Math.max(0, transport.pending())); // Force generation of TRANSPORT_HEAD_CLOSE (not in C code)
private void writeToNetwork(EngineConnection engineConnection) { final String methodName = "writeToNetwork"; logger.entry(this, methodName, engineConnection); if (engineConnection.transport.pending() > 0) { ByteBuffer head = engineConnection.transport.head(); int amount = head.remaining(); engineConnection.channel.write(head, new NetworkWritePromiseImpl(this, amount, engineConnection)); engineConnection.transport.pop(amount); engineConnection.transport.tick(System.currentTimeMillis()); } logger.exit(this, methodName); }
transport.close_tail(); transport.close_head(); transport.pop(transport.pending());
transport.close_tail(); transport.close_head(); transport.pop(transport.pending()); // Force generation of TRANSPORT_HEAD_CLOSE (not in C code)
transport.close_tail(); transport.close_head(); transport.pop(Math.max(0, transport.pending())); // Force generation of TRANSPORT_HEAD_CLOSE (not in C code)
@Override public void run(Selectable selectable) { Reactor reactor = selectable.getReactor(); Transport transport = ((SelectableImpl)selectable).getTransport(); int pending = transport.pending(); if (pending > 0) { SocketChannel channel = (SocketChannel)selectable.getChannel(); try { int n = channel.write(transport.head()); if (n < 0) { transport.close_head(); } else { transport.pop(n); } } catch(IOException ioException) { ErrorCondition condition = new ErrorCondition(); condition.setCondition(Symbol.getSymbol("proton:io")); condition.setDescription(ioException.getMessage()); transport.setCondition(condition); transport.close_head(); } } int newPending = transport.pending(); if (newPending != pending) { update(selectable); reactor.update(selectable); } } };
@Override public void run(Selectable selectable) { Reactor reactor = selectable.getReactor(); Transport transport = ((SelectableImpl)selectable).getTransport(); int pending = transport.pending(); if (pending > 0) { SocketChannel channel = (SocketChannel)selectable.getChannel(); try { int n = channel.write(transport.head()); if (n < 0) { transport.close_head(); } else { transport.pop(n); } } catch(IOException ioException) { ErrorCondition condition = new ErrorCondition(); condition.setCondition(Symbol.getSymbol("proton:io")); condition.setDescription(ioException.getMessage()); transport.setCondition(condition); transport.close_head(); } } int newPending = transport.pending(); if (newPending != pending) { update(selectable); reactor.update(selectable); } } };
engineConnection.requestor.tell(new DrainNotification(), this); if (engineConnection.transport.pending() > 0) { writeToNetwork(engineConnection);