Exemple #1
0
 public static TcpSocketSaeaServer CreateServerAgent(
     TcpSocketSaeaSessionType saeaSessionType,
     TcpSocketSaeaServerConfiguration configuration,
     NotifyEventHandler <TcpSocketCompletionNotify, TcpSocketSaeaSession> completetionNotify)
 {
     configuration._intervalWhetherService = true;
     return(new TcpSocketSaeaServer(saeaSessionType, configuration, completetionNotify));
 }
 public static TcpSocketSaeaClientAgent CreateClientAgent(
     TcpSocketSaeaSessionType saeaSessionType,
     TcpSocketSaeaClientConfiguration configuration,
     NotifyEventHandler <TcpSessionNotify, TcpSocketSaeaSession> completetionNotify)
 {
     configuration._intervalWhetherService = false;
     return(new TcpSocketSaeaClientAgent(saeaSessionType, configuration, completetionNotify));
 }
 internal TcpSocketSaeaClientAgent(
     TcpSocketSaeaSessionType saeaSessionType,
     TcpSocketSaeaClientConfiguration configuration,
     NotifyEventHandler <TcpSocketCompletionNotify, TcpSocketSaeaSession> completetionNotify)
     : base(saeaSessionType, configuration, completetionNotify)
 {
     if (configuration.AppKeepAlive &&
         saeaSessionType == TcpSocketSaeaSessionType.Packet)
     {
         var keepAliveThread = new Thread(AppKeepAliveWorkThread);
         keepAliveThread.IsBackground = true;
         keepAliveThread.Start();
     }
 }
Exemple #4
0
        internal TcpSocketSaeaEngineBased(
            TcpSocketSaeaSessionType saeaSessionType,
            TcpSocketConfigurationBase configuration,
            NotifyEventHandler <TcpSessionNotify, TcpSocketSaeaSession> completetionNotify)
        {
            TcpSocketSaeaSessions = new List <TcpSocketSaeaSession>();
            HandlerSaeaPool       = new SaeaAwaiterPool();
            SessionPool           = new SessionPool();

            SaeaSessionType    = saeaSessionType;
            Configuration      = configuration;
            CompletetionNotify = completetionNotify;

            HandlerSaeaPool.Initialize(() => new SaeaAwaiter(),
                                       (saea) =>
            {
                try
                {
                    saea.Saea.AcceptSocket = null;
                    saea.Saea.SetBuffer(EmptyArray, 0, EmptyArray.Length);
                    saea.Saea.RemoteEndPoint = null;
                    saea.Saea.SocketFlags    = SocketFlags.None;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("server_clean awaiter info:" + ex.Message);
                }
            },
                                       50);
            if (saeaSessionType == TcpSocketSaeaSessionType.Full)
            {
                SessionPool.Initialize(() => new TcpSocketSaeaFullBased(Configuration, HandlerSaeaPool, SessionPool, completetionNotify, this),
                                       (session) =>
                {
                    session.Detach();
                }, 50);
            }
            else
            {
                SessionPool.Initialize(() => new TcpSocketSaeaPackBased(Configuration, HandlerSaeaPool, SessionPool, completetionNotify, this),
                                       (session) =>
                {
                    session.Detach();
                }, 50);
            }
        }