public StreamSendRequest(PendingSendStream stream, long length)
        {
            Require.NotNull(stream, "stream");

            _stream = stream;
            _length = length;
        }
        public int RegisterStream(Stream stream, string streamName, string contentType, int? associationId)
        {
            Require.NotNull(stream, "stream");

            if (_streams.Count == MaxAssociationId)
                throw new ProtoChannelException("No stream association ID's are available");

            stream.Position = 0;

            var protoStream = new PendingSendStream(
                stream.Length, streamName, contentType, GetNextAssociationId(associationId), stream
            );

            _streams.Add(protoStream.AssociationId, protoStream);

            return protoStream.AssociationId;
        }
        public int RegisterStream(Stream stream, string streamName, string contentType, StreamDisposition disposition, int? associationId)
        {
            Require.NotNull(stream, "stream");

            if (_streams.Count == MaxAssociationId)
                throw new ProtoChannelException("No stream association ID's are available");

            // Setting the position throws when the stream cannot be seeked,
            // even when the position already is 0.

            if (stream.Position != 0)
                stream.Position = 0;

            var protoStream = new PendingSendStream(
                stream.Length, streamName, contentType, disposition, GetNextAssociationId(associationId), stream
            );

            _streams.Add(protoStream.AssociationId, protoStream);

            return protoStream.AssociationId;
        }
        private void RemoveStream(PendingSendStream stream)
        {
            // The stream is not removed from the queue. Processing the queue
            // knows that it should skip disposed streams.

            _streams.Remove(stream.AssociationId);

            stream.Dispose();
        }
        public void RemoveStream(PendingSendStream stream)
        {
            Require.NotNull(stream, "stream");

            if (_streams.ContainsKey(stream.AssociationId))
            {
                // The stream is not removed from the queue. Processing the queue
                // knows that it should skip disposed streams.

                _streams.Remove(stream.AssociationId);

                stream.Dispose();
            }
        }