public MemoryStream GetStream(string tag, byte[] buffer, int offset, int count)
 {
     var stream = new RecyclableMemoryStream(this, tag, count);
     stream.Write(buffer, offset, count);
     stream.Position = 0;
     return stream;
 }
コード例 #2
0
ファイル: TcpSocket.cs プロジェクト: mtf30rob/csharp-driver
 /// <summary>
 /// Sends data asynchronously
 /// </summary>
 public void Write(RecyclableMemoryStream stream, Action onBufferFlush)
 {
     Interlocked.Exchange(ref _writeFlushCallback, onBufferFlush);
     if (_isClosing)
     {
         OnError(new SocketException((int)SocketError.Shutdown));
         OnWriteFlushed();
         return;
     }
     if (_sendSocketEvent != null)
     {
         _sendSocketEvent.BufferList = stream.GetBufferList();
         var isWritePending = false;
         try
         {
             isWritePending = _socket.SendAsync(_sendSocketEvent);
         }
         catch (Exception ex)
         {
             OnError(ex);
         }
         if (!isWritePending)
         {
             OnSendCompleted(this, _sendSocketEvent);
         }
     }
     else
     {
         var length = (int) stream.Length;
         _socketStream.BeginWrite(stream.GetBuffer(), 0, length, OnSendStreamCallback, null);
     }
 }