Beispiel #1
0
 internal void ProcessSendMessages()
 {
     IBuffer[] items;
     if (IsDisposed)
     {
         return;
     }
     if (System.Threading.Interlocked.CompareExchange(ref mSendStatus, 1, 0) == 0)
     {
         BufferLink bufferLink = new BufferLink();
         object     data       = DequeueSendMessage();
         if (data == null)
         {
             System.Threading.Interlocked.Exchange(ref mSendStatus, 0);
             return;
         }
         PipeStream pipStream = 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, pipStream);
             }
             data = DequeueSendMessage();
         }
         if (SSL && pipStream.CacheLength > 0)
         {
             pipStream.Flush();
         }
         IBuffer streamBuffer = mBaseNetStream.GetWriteCacheBufers();
         bufferLink.Import(streamBuffer);
         if (bufferLink.First != null)
         {
             CommitBuffer(bufferLink.First);
         }
         else
         {
             System.Threading.Interlocked.Exchange(ref mSendStatus, 0);
         }
     }
 }
Beispiel #2
0
        private void ProcessSendMessages()
        {
            IBuffer[] items;
            object    data = DequeueSendMessage();

            if (data == null)
            {
                FreeSend();
                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
            {
                FreeSend();
            }
        }
Beispiel #3
0
 internal void ProcessSendMessages()
 {
     IBuffer[] items;
     if (IsDisposed || mCount == 0)
     {
         return;
     }
     if (System.Threading.Interlocked.CompareExchange(ref mSendStatus, 1, 0) == 0)
     {
         BufferLink bufferLink = new BufferLink();
         object     data       = DequeueSendMessage();
         PipeStream pipStream  = Stream.ToPipeStream();
         while (data != null)
         {
             if (data is IBuffer)
             {
                 bufferLink.Import((IBuffer)data);
             }
             else
             {
                 WriterData(data, pipStream);
             }
             data = DequeueSendMessage();
         }
         if (SSL && pipStream.CacheLength > 0)
         {
             pipStream.Flush();
         }
         IBuffer streamBuffer = mBaseNetStream.GetWriteCacheBufers();
         bufferLink.Import(streamBuffer);
         if (bufferLink.First != null)
         {
             CommitBuffer(bufferLink.First);
         }
         else
         {
             System.Threading.Interlocked.Exchange(ref mSendStatus, 0);
             if (!mSendMessages.IsEmpty)
             {
                 ProcessSendMessages();
             }
         }
     }
 }
Beispiel #4
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);
        }
Beispiel #5
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();
             }
         }
     }
 }