public virtual void FinishWrite(SocketChannelAsyncOperation operation)
 {
     try
     {
         operation.Validate();
         this.inFlush = false;
     }
     catch (Exception ex)
     {
         Debug.LogError("write data error in FinishWrite" + ex);
     }
     this.Flush();//如果还有数据的话会再次写入
 }
        public virtual void FinishRead(SocketChannelAsyncOperation operation)
        {
            bool close = false;

            try
            {
                int         received  = operation.BytesTransferred;
                SocketError errorCode = operation.SocketError;

                switch (errorCode)
                {
                case SocketError.Success:
                    if (received == 0)
                    {
                        close = true;     // indicate that socket was closed
                    }
                    else
                    {
                        try
                        {
                            Pipeline.FireChannelRead(operation.Buffer, operation.Offset, received);
                        }
                        catch (Exception ex)
                        {
                            Debug.LogError("Pipeline hander error" + ex);
                        }
                    }
                    break;

                default:
                    throw new SocketException((int)errorCode);
                }
                if (this.state == StateFlags.Active)
                {
                    this.Receive();
                }
                if (close)
                {
                    Debug.LogError("connect error in FinishRead");
                    this.ConnectError();
                }
            }
            catch (Exception ex)
            {   //当服务器关闭的时候会触发这个
                Debug.LogError("read data error in FinishRead" + ex);
                this.ConnectError();
            }
        }
 public virtual void FinishConnect(SocketChannelAsyncOperation operation)
 {
     if (this.state == StateFlags.Active)
     {
         return;
     }
     this.state = StateFlags.Active;
     try
     {
         if (operation != null)
         {
             operation.Validate();
         }
         this.Receive();
         this.Pipeline.FireChannelActive();
     }
     catch (Exception ex)
     {
         Debug.LogError("connect error in finishconnect" + ex);
         this.ConnectError();
     }
 }