public void accept(final Pooled<ByteBuffer> pooledBuffer, final boolean eof) throws IOException { try { final ByteBuffer buffer = pooledBuffer.getResource(); final ConnectedMessageChannel messageChannel = channel.getRemoteConnection().getChannel(); if (eof) { // EOF flag (sync close) buffer.put(7, (byte) (buffer.get(7) | Protocol.MSG_FLAG_EOF)); log.tracef("Sending message (with EOF) (%s) to %s", buffer, messageChannel); } if (cancelled) { buffer.put(7, (byte) (buffer.get(7) | Protocol.MSG_FLAG_CANCELLED)); buffer.limit(8); // discard everything in the buffer log.trace("Message includes cancel flag"); } synchronized (OutboundMessage.this) { int msgSize = buffer.remaining(); window -= msgSize; while (window < msgSize) { try { log.trace("Message window is closed, waiting"); OutboundMessage.this.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new InterruptedIOException("Interrupted on write"); } } log.trace("Message window is open, proceeding with send"); } Channels.sendBlocking(messageChannel, buffer); } finally { pooledBuffer.free(); if (eof) { channel.free(OutboundMessage.this); } } }
public void flush() throws IOException { log.trace("Flushing message channel"); Channels.flushBlocking(channel.getRemoteConnection().getChannel()); }