Class ChannelAsyncOutputStream

    • Field Detail

      • writeState

        protected final ChannelAsyncOutputStream.WriteState writeState
        Encapsulates the state of the current write operation. Access is always under lock (on writeState's monitor), the lock is held only shortly and never while writing.
    • Constructor Detail

      • ChannelAsyncOutputStream

        public ChannelAsyncOutputStream​(Channel channel,
                                        byte cmd,
                                        boolean sendChunkIfRemoteWindowIsSmallerThanPacketSize)
        Parameters:
        channel - The Channel through which the stream is communicating
        cmd - Either SSH_MSG_CHANNEL_DATA or SSH_MSG_CHANNEL_EXTENDED_DATA indicating the output stream type
        sendChunkIfRemoteWindowIsSmallerThanPacketSize - Determines the chunking behaviour, if the remote window size is smaller than the packet size. Can be used to establish compatibility with certain clients, that wait until the window size is 0 before adjusting it.
        See Also:
        SSHD-1123
    • Method Detail

      • writeBuffer

        public IoWriteFuture writeBuffer​(Buffer buffer)
                                  throws IOException
        This write operation is asynchronous: if there is not enough window space, it may keep the write pending or write only part of the buffer and keep the rest pending. Concurrent writes are not allowed and will throw a WritePendingException. Any subsequent write must occur only once the returned future is fulfilled; for instance triggered via a listener on the returned future. Try to avoid doing a subsequent write directly in a future listener, though; doing so may lead to deep chains of nested listener calls with deep stack traces, and may ultimately lead to a stack overflow.
        Specified by:
        writeBuffer in interface IoOutputStream
        Throws:
        WritePendingException - if a concurrent write is attempted
        IOException
      • shutdown

        protected void shutdown()
      • doWriteIfPossible

        protected void doWriteIfPossible​(boolean resume)
      • writePacket

        protected IoWriteFutureImpl writePacket​(IoWriteFutureImpl future,
                                                boolean resume)
        Try to write as much of the current buffer as possible. If the buffer is larger than the packet size split it in packets, writing one after the other by chaining futures. If there is not enough window space, stop writing. Writing will be resumed once the window has been enlarged again.
        Parameters:
        future - IoWriteFutureImpl for the current write
        resume - whether being called in response to a remote window adjustment
        Returns:
        null if all written, or if the rest will be written via a future listener. Otherwise a future for the remaining writes.
      • createSendBuffer

        protected Buffer createSendBuffer​(Buffer buffer,
                                          Channel channel,
                                          long length)
      • isSendChunkIfRemoteWindowIsSmallerThanPacketSize

        public boolean isSendChunkIfRemoteWindowIsSmallerThanPacketSize()
      • setSendChunkIfRemoteWindowIsSmallerThanPacketSize

        public void setSendChunkIfRemoteWindowIsSmallerThanPacketSize​(boolean sendChunkIfRemoteWindowIsSmallerThanPacketSize)