Esempio n. 1
0
            public static void OnReceive(socket socket, type type, int value)
            {
                try
                {
                    switch (type)
                    {
                    case tryReceiver.type.ServerOnReceiveStreamCommandLength: new unionType {
                            Value = socket
                    }.TcpCommandServerSocket.OnReceiveStreamCommandLength(value); return;

                    case tryReceiver.type.ServerOnReceiveStreamIdentityCommand: new unionType {
                            Value = socket
                    }.TcpCommandServerSocket.OnReceiveStreamIdentityCommand(value); return;

                    case tryReceiver.type.ServerOnReceiveStreamCommand: new unionType {
                            Value = socket
                    }.TcpCommandServerSocket.OnReceiveStreamCommand(value); return;

                    case tryReceiver.type.ClientOnReceiveIdentity: new unionType {
                            Value = socket
                    }.TcpCommandClientSocket.OnReceiveIdentity(value); return;
                    }
                }
                catch (Exception error)
                {
                    fastCSharp.log.Error.Add(error, null, false);
                }
            }
 /// <summary>
 /// 数据接收完成后的回调委托
 /// </summary>
 /// <param name="socket">异步套接字</param>
 public void CallOnSend(socket socket)
 {
     if (socket.receiveError == null)
     {
         OnSend(true);
     }
     else
     {
         Socket.Dispose();
         OnSend(false);
     }
 }
Esempio n. 3
0
            private void push(int value)
            {
                socket socket = Socket;
                type   type   = Type;

                Socket = null;
                try
                {
                    typePool <tryReceiver> .PushNotNull(this);
                }
                finally { OnReceive(socket, type, value); }
            }
Esempio n. 4
0
 /// <summary>
 /// 异步回调
 /// </summary>
 /// <param name="isReceive">数据接收是否成功</param>
 /// <param name="async">异步回调参数</param>
 private void callback(bool isReceive, SocketAsyncEventArgs async)
 {
     Socket = null;
     if (async == null)
     {
         push(isReceive);
     }
     else
     {
         try
         {
             async.Completed -= asyncCallback;
             socketAsyncEventArgs.PushNotNull(async);
         }
         finally
         {
             push(isReceive);
         }
     }
 }
Esempio n. 5
0
            /// <summary>
            /// 接收数据
            /// </summary>
            public void Receive(socket socket, type type, DateTime timeout)
            {
                SocketAsyncEventArgs async = null;

                Socket  = socket;
                Type    = type;
                Timeout = timeout;
                try
                {
                    async            = socketAsyncEventArgs.Get();
                    async.UserToken  = this;
                    async.Completed += asyncCallback;
                    if (receive(async))
                    {
                        return;
                    }
                }
                catch (Exception error)
                {
                    socket.lastException = error;
                }
                this.callback(async);
            }