示例#1
0
 protected void IO_Completed(object sender, SocketAsyncEventArgs args)
 {
     //操作成功
     if (args.SocketError == SocketError.Success)
     {
         ChannelSocketAsyncEventArgs eargs = args as ChannelSocketAsyncEventArgs;
         ProcessCompleted(eargs);
         return;
     }
     //收到断开连接的请求
     else if (args.SocketError == SocketError.ConnectionReset)
     {
         Trace.WriteLine($"args.SocketError: SocketError.ConnectionReset");
         Shutdown();
         return;
     }
     else if (args.SocketError == SocketError.WouldBlock)
     {
         Trace.WriteLine($"args.SocketError: SocketError.WouldBlock");
     }
     else
     {
         Trace.WriteLine($"args.SocketError:{ args.SocketError }");
         Shutdown();
         return;
     }
 }
示例#2
0
        private void ProcessSend(ChannelSocketAsyncEventArgs args)
        {
            if (args.Buffer != null)
            {
                args.SetBuffer(null, 0, 0);
            }

            invoker.fireOnChannelSend(args.ByteBuf, ExitAndTrySending);
        }
示例#3
0
        public AbstractSocketChannel()
        {
            this.sendingSocketAsyncEventArgs   = new ChannelSocketAsyncEventArgs();
            this.receivingSocketAsyncEventArgs = new ChannelSocketAsyncEventArgs();

            this.sendingSocketAsyncEventArgs.Completed   += IO_Completed;
            this.receivingSocketAsyncEventArgs.Completed += IO_Completed;

            config = new ChannelConfig();
        }
示例#4
0
 public TcpClientChannel()
 {
     this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
     {
         Blocking = false,
         NoDelay  = true
     };
     connectEventArgs            = new ChannelSocketAsyncEventArgs();
     connectEventArgs.Completed += IO_Completed;
 }
示例#5
0
 /// <summary>
 /// 接收完成并处理数据
 /// </summary>
 /// <param name="args"></param>
 private void ProcessReceive(ChannelSocketAsyncEventArgs args)
 {
     try
     {
         if (args.BytesTransferred > 0)
         {
             IByteBuf buf = args.ByteBuf;
             buf.SetWriteIndex(args.BytesTransferred);
             invoker.fireOnChannelRead(buf, ExitAndTryReceiving);
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine("processReceive.Unpacking:" + ex.Message);
         Shutdown();
     }
 }
示例#6
0
        protected virtual void ProcessCompleted(ChannelSocketAsyncEventArgs args)
        {
            switch (args.LastOperation)
            {
            case SocketAsyncOperation.Receive:
                ProcessReceive(args);
                break;

            case SocketAsyncOperation.Send:
                ProcessSend(args);
                break;

            case SocketAsyncOperation.Disconnect:
                Trace.WriteLine("Disconnect");
                break;

            default:
                Trace.WriteLine("default");
                break;
            }
        }
示例#7
0
        private void ProcessConnect(ChannelSocketAsyncEventArgs args)
        {
            var channel = NewChannelFactory(args.ConnectSocket);

            invoker.fireOnChannelRead(channel);
        }