示例#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);
         }
     }
 }
示例#2
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();
             }
         }
     }
 }