@Override public void outputDone(int bytes) { synchronized (lock) { transport.pop(bytes); offset -= bytes; if (offset < 0) { throw new IllegalStateException("You called outputDone for more bytes than you actually received. numberOfBytes=" + bytes + ", outcome result=" + offset); } } flush(); }
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 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; }
if (wrote > 0) { processed = true; _transport.pop(wrote); } else { writeBlocked = true;
public void flushBytes() { for (EventHandler handler : handlers) { if (!handler.flowControl(readyListener)) { return; } } lock.lock(); try { while (true) { ByteBuffer head = transport.head(); int pending = head.remaining(); if (pending <= 0) { break; } // We allocated a Pooled Direct Buffer, that will be sent down the stream ByteBuf buffer = PooledByteBufAllocator.DEFAULT.directBuffer(pending); buffer.writeBytes(head); for (EventHandler handler : handlers) { handler.pushBytes(buffer); } transport.pop(pending); } } finally { lock.unlock(); } }
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());
private void actualFlush() { requireHandler(); for (EventHandler handler : handlers) { if (!handler.flowControl(readyListener)) { scheduledFlush = false; return; } } try { while (true) { ByteBuffer head = transport.head(); int pending = head.remaining(); if (pending <= 0) { break; } // We allocated a Pooled Direct Buffer, that will be sent down the stream ByteBuf buffer = PooledByteBufAllocator.DEFAULT.directBuffer(pending); buffer.writeBytes(head); for (EventHandler handler : handlers) { handler.pushBytes(buffer); } transport.pop(pending); } } finally { scheduledFlush = false; } }
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); } } };