Inheritance: IDisposable
 internal void AttachToIoThread(TransportPipe pipe, int threadNumber = 0)
 {
     if(threadNumber >= _sendingThreads.Count)
         throw new ArgumentException("Sending Thread number exceeds the number of sending threads");
     _sendingThreads[threadNumber].Attach(pipe);
     _pipesToThreadNumber[pipe] = threadNumber;
 }
 public void Detach(TransportPipe pipe)
 {
     var waitHandle = new AutoResetEvent(false);
     _commands.Add(() =>
                       {
                           RemovePipe(pipe);
                           waitHandle.Set();
                       });
     waitHandle.WaitOne();
 }
 internal void Attach(TransportPipe pipe)
 {
     _commands.Add(() =>
     {
         var socketAsyncEventArgs = new SocketAsyncEventArgs();
         var sendingPipeInfo = new SendingPipeInfo(pipe, socketAsyncEventArgs);
         socketAsyncEventArgs.UserToken = sendingPipeInfo;
         socketAsyncEventArgs.Completed += OnSendCompleted;
         _transportPipes.Add(sendingPipeInfo);
         CreateSocketForEndpoint(sendingPipeInfo);
     });
 }
 public SendingPipeInfo(TransportPipe pipe, SocketAsyncEventArgs eventArgs)
 {
     Pipe = pipe;
     EventArgs = eventArgs;
 }
 private void RemovePipe(TransportPipe pipe)
 {
     var pipeInfo = _transportPipes.Single(x => x.Pipe == pipe);
     _transportPipes.Remove(pipeInfo);
     var socket = pipeInfo.Socket;
     if (socket != null)
         socket.Dispose();
 }
 public void DetachFromIoThread(TransportPipe pipe)
 {
     var threadNumber = _pipesToThreadNumber[pipe];
     _sendingThreads[threadNumber].Detach(pipe);
 }