Exemplo n.º 1
0
        private void FlushProxyStream(bool end)
        {
            IBuffer buffer = mProxyStream.GetWriteCacheBufers();

            if (buffer != null)
            {
                if (Request.Session.SSL)
                {
                    mProxyStream.Import(buffer);
                    var length = (int)mProxyStream.Length;
                    var data   = System.Buffers.ArrayPool <byte> .Shared.Rent(length);

                    mProxyStream.Read(data, 0, length);
                    ProxyDataBuffer proxyData = new ProxyDataBuffer(new ArraySegment <byte>(data, 0, length));
                    Request.Session.Send(proxyData);
                }
                else
                {
                    Request.Session.Send(buffer);
                }
            }
            if (end)
            {
                mProxyStream.Dispose();
            }
        }
Exemplo n.º 2
0
        private void ProcessSendMessages()
        {
            IBuffer[] items;
            if (System.Threading.Interlocked.CompareExchange(ref mSendStatus, 1, 0) == 0)
            {
                object data = DequeueSendMessage();
                if (data == null)
                {
                    System.Threading.Interlocked.Exchange(ref mSendStatus, 0);
                    return;
                }
                BufferLink bufferLink = new BufferLink();
                PipeStream pipeStream = Stream.ToPipeStream();
                while (data != null)
                {
                    if (data is IBuffer)
                    {
                        bufferLink.Import((IBuffer)data);
                    }
                    else if (data is IBuffer[])
                    {
                        items = (IBuffer[])data;
                        for (int i = 0; i < items.Length; i++)
                        {
                            bufferLink.Import(items[i]);
                        }
                    }
                    else if (data is IEnumerable <IBuffer> )
                    {
                        foreach (IBuffer item in (IEnumerable <IBuffer>)data)
                        {
                            bufferLink.Import(item);
                        }
                    }
                    else
                    {
                        WriterData(data, pipeStream);
                    }
                    data = DequeueSendMessage();
                }
                if (SSL && pipeStream.CacheLength > 0)
                {
                    pipeStream.Flush();
                }
                IBuffer mstreambuffer = mBaseNetworkStream.GetWriteCacheBufers();
                bufferLink.Import(mstreambuffer);

                if (bufferLink.First != null)
                {
                    CommitBuffer(bufferLink.First);
                }
                else
                {
                    System.Threading.Interlocked.Exchange(ref mSendStatus, 0);
                }
            }
        }
Exemplo n.º 3
0
        public TcpClient SendMessage(object msg)
        {
            IBuffer[] items;
            bool      isnew;

            Connect(out isnew);
            lock (mBaseNetworkStream)
            {
                BufferLink bufferLink = new BufferLink();
                if (msg != null)
                {
                    if (msg is IBuffer)
                    {
                        bufferLink.Import((IBuffer)msg);
                    }
                    else if (msg is IBuffer[])
                    {
                        items = (IBuffer[])msg;
                        for (int i = 0; i < items.Length; i++)
                        {
                            bufferLink.Import(items[i]);
                        }
                    }
                    else
                    {
                        PipeStream pipeStream = Stream.ToPipeStream();
                        WriterData(msg, pipeStream);
                        if (SSL)
                        {
                            pipeStream.Flush();
                        }
                    }
                }
                IBuffer writeBuffer = mBaseNetworkStream.GetWriteCacheBufers();
                bufferLink.Import(writeBuffer);
                if (bufferLink.First != null)
                {
                    OnWriterFlash(bufferLink.First);
                }
            }
            return(this);
        }
Exemplo n.º 4
0
 private void ProcessSendMessages()
 {
     if (System.Threading.Interlocked.CompareExchange(ref mSendStatus, 1, 0) == 0)
     {
         object     data       = DequeueSendMessage();
         BufferLink bufferLink = new BufferLink();
         PipeStream pipeStream = Stream.ToPipeStream();
         while (data != null)
         {
             if (data is IBuffer)
             {
                 bufferLink.Import((IBuffer)data);
             }
             else
             {
                 WriterData(data, pipeStream);
             }
             data = DequeueSendMessage();
         }
         if (SSL && pipeStream.CacheLength > 0)
         {
             pipeStream.Flush();
         }
         IBuffer mstreambuffer = mBaseNetworkStream.GetWriteCacheBufers();
         bufferLink.Import(mstreambuffer);
         if (bufferLink.First != null)
         {
             CommitBuffer(bufferLink.First);
         }
         else
         {
             System.Threading.Interlocked.Exchange(ref mSendStatus, 0);
             if (!mSendMessageQueue.IsEmpty)
             {
                 ProcessSendMessages();
             }
         }
     }
 }
Exemplo n.º 5
0
        public static void Copy(PipeStream source, Stream dest)
        {
            IBuffer buff = source.GetWriteCacheBufers();

            WriteBuffer(dest, buff);
        }