Пример #1
0
        /// <summary>
        /// On a web resource stream being compressed.
        /// </summary>
        protected void StartSendStream(MemoryStream stream, WebResource resource)
        {
            try {
                // replace the resource stream with the compressed bytes
                resource.ReplaceStreamLocked(stream, _header.Compression);

                // is the stream to be encrypted? yes, encrypt it
                if (_header.EncryptionPassword != null)
                {
                    stream = Crypto.EncryptWithPassword(stream, _header.EncryptionPassword);
                }

                EnqueueHeader((int)stream.Length);

                // send the stream
                AsyncSocket.Enqueue(stream, (int)stream.Length);

                stream.Dispose();

                AsyncSocket.Send(_onSent);
                _onSent = null;
            } finally {
                // release the lock
                _lock.Release();
            }
        }
Пример #2
0
        /// <summary>
        /// On the stream being compressed.
        /// </summary>
        protected void StartSendStream(MemoryStream stream, WebResource resource)
        {
            // replace the resource stream with the compressed bytes
            resource.ReplaceStreamLocked(stream, _compression);

            SendHeaders((int)stream.Length);

            Log.Info("Sending stream of length '" + stream.Length + "' to client " + this + ".");

            // send the stream
            Socket.Send(stream, (int)stream.Length);

            stream.Dispose();

            // is the callback set?
            if (_onSent != null)
            {
                // yes, run it
                var onSent = _onSent;
                _onSent = null;
                _lock.Release();
                onSent.Run();
            }
            else
            {
                // no, release the lock
                _lock.Release();
            }
        }
Пример #3
0
        /// <summary>
        /// Start sending the stream. The client is locked until the stream is complete.
        /// </summary>
        protected void StartSendStream(Stream stream, int length, WebResource resource)
        {
            // yes, does the buffer need to be compressed?
            if (_defaultCompression == resource.Compression)
            {
                // send the headers with the stream length
                SendHeaders((int)stream.Length);

                Log.Info("Sending stream of length '" + length + "' to client " + this + ".");

                // no, the resource compression matches the required compression

                // send the stream
                Socket.Send(stream, length);

                // is the callback set?
                if (_onSent != null)
                {
                    // yes, run it
                    var onSent = _onSent;
                    _onSent = null;
                    _lock.Release();
                    onSent.Run();
                }
                else
                {
                    // no, release the lock
                    _lock.Release();
                }
            }
            else
            {
                // is the web resource compressed?
                if (resource.Compression != DecompressionMethods.None)
                {
                    // yes, decompress the resource and replace the web resource stream
                    resource.ReplaceStreamLocked(StreamHelper.Decompress(resource.Compression, stream, ref length), DecompressionMethods.None);
                }

                // yes, compress the bytes
                StreamHelper.Compress(Act.New(StartSendStream, (MemoryStream)null, resource), _defaultCompression,
                                      System.IO.Compression.CompressionLevel.Fastest, stream, length, false);
            }
        }
Пример #4
0
        /// <summary>
        /// Start sending the stream. The client is locked until the stream is complete.
        /// </summary>
        protected void StartSendStream(Stream stream, int length, WebResource resource)
        {
            // yes, does the buffer need to be compressed?
            if (_defaultCompression == resource.Compression)
            {
                // no, the resource compression matches the required compression

                // is the stream to be encrypted? yes, encrypt it
                if (_header.EncryptionPassword != null)
                {
                    stream = Crypto.EncryptWithPassword(stream, _header.EncryptionPassword);
                    length = (int)stream.Length;
                }

                try {
                    // send the headers with the stream length
                    EnqueueHeader(length);

                    // send the stream
                    AsyncSocket.Enqueue(stream, length);
                    AsyncSocket.Send(_onSent);
                } finally {
                    _onSent = null;
                    _lock.Release();
                }
            }
            else
            {
                // is the web resource compressed?
                if (resource.Compression != DecompressionMethods.None)
                {
                    // yes, decompress the resource and replace the web resource stream
                    resource.ReplaceStreamLocked(StreamHelper.Decompress(resource.Compression, stream, ref length), DecompressionMethods.None);
                }

                // yes, compress the bytes
                StreamHelper.Compress(Act.New(StartSendStream, (MemoryStream)null, resource), _defaultCompression,
                                      System.IO.Compression.CompressionLevel.Fastest, stream, length, false);
            }
        }