Esempio n. 1
0
        public ClientEnd(EventLoop loop, string host, int port)
        {
            _loop    = loop;
            _channel = new Channel();
            _handle  = new Tcp(_loop);
            _ip      = new IPEndPoint(IPAddress.Parse(host), port);

            _handle.Channel = _channel;
            _channel.Handle = _handle;
            _connected      = false;
        }
Esempio n. 2
0
        public TcpHandle(EventLoop loop) : base()
        {
            _handle    = Libuv.Allocate(uv_handle_type.UV_TCP);
            _eventLoop = loop;

            Libuv.uv_tcp_init(loop.Loop, _handle);

            GCHandle gcHandle = GCHandle.Alloc(this, GCHandleType.Normal);

            ((uv_handle_t *)_handle)->data = GCHandle.ToIntPtr(gcHandle);
        }
Esempio n. 3
0
        public ClientProxy(EventLoop loop, List <ServerCfg> servers)
        {
            _eventLoop = loop;
            _clientRpc = new ClientEnd[servers.Count];

            for (int idx = 0; idx < servers.Count; idx++)
            {
                var cfg = servers[idx];
                _clientRpc[idx] = new ClientEnd(_eventLoop, cfg.host, cfg.port);
            }
        }
Esempio n. 4
0
        public ServerEnd(EventLoop loop, IDispatcher dispatcher, int port)
        {
            _netLoop = loop;
            //IPEndPoint ep = new IPEndPoint(IPAddress.Any, _port);
            _tcpHandle = new TcpListen(_netLoop);

            _tcpHandle.ChannelAddEvent += AddChannel;

            _ip = new IPEndPoint(IPAddress.Any, port);
            _tcpHandle.Bind(_ip);
            _dispatcher = dispatcher;

            //_dispatcher = new Dispatcher(_loop);
        }
Esempio n. 5
0
        public Timer(EventLoop loop, Action <object> cb, object state)
        {
            _eventLoop = loop;
            _callback  = cb;
            _state     = state;

            _handle = Libuv.Allocate(uv_handle_type.UV_TIMER);

            Libuv.uv_timer_init(_eventLoop.Loop, _handle);


            GCHandle gcHandle = GCHandle.Alloc(this, GCHandleType.Normal);

            ((uv_handle_t *)_handle)->data = GCHandle.ToIntPtr(gcHandle);
        }
Esempio n. 6
0
        public Async(EventLoop loop, Action <object> cb, object state)
        {
            var handle = Libuv.Allocate(uv_handle_type.UV_ASYNC);

            _handle = handle;

            _eventLoop = loop;

            _callback = cb;
            _state    = state;


            Libuv.uv_async_init(loop.Loop, _handle, WorkCallback);

            GCHandle gcHandle = GCHandle.Alloc(this, GCHandleType.Normal);

            ((uv_handle_t *)_handle)->data = GCHandle.ToIntPtr(gcHandle);
        }
Esempio n. 7
0
        public RemoteServers(EventLoop eventLoop)
        {
            _maps.Add("area", AREA);
            _maps.Add("connector", CONNECTOR);
            _maps.Add("chat", CHAT);
            _maps.Add("gate", GATE);

            foreach (var kv in _maps)
            {
                var cfg = CfgMgr.Instance.GetServerCfg(kv.Key);
                _servers[kv.Value] = new ClientProxy(eventLoop, cfg);
            }


            /*
             * for(int idx = 0; idx < SERVER_NUM; idx++)
             * {
             *  _servers[idx] = new ClientProxy( )
             * }
             */
        }
Esempio n. 8
0
        void HandlePacket(EventLoop netloop, Channel c, Packet p)
        {
            if (_workLoop != netloop)
            {
                _workLoop.AddAsyncJob(() =>
                {
                    //byte[] buff = loop.PWriter.Write("abcde");

                    //c.Send("abcde",loop.PWriter);

                    int xx;
                    string bbb;
                    switch (p.serviceId)
                    {
                    case 1:
                        break;

                    default:
                        break;
                    }

                    netloop.AddAsyncJob(() =>
                    {
                        c.Send();
                    });

                    //c.Send()
                });
            }
            else
            {
                Packet ret = new Packet();
                //byte[] buff = loop.PWriter.Write("abcde");
                //c.Send(buff);
                //c.Send("abcde",loop.PWriter);
            }
        }
Esempio n. 9
0
 public Tcp(EventLoop loop) : base(loop)
 {
 }
Esempio n. 10
0
 public Dispatcher(EventLoop loop)
 {
     _workLoop     = loop;
     _remoteServer = new RemoteServers(loop);
 }
Esempio n. 11
0
 public RpcClient(EventLoop loop)
 {
     _eventLoop     = loop;
     _remoteServers = new RemoteServers(_eventLoop);
 }
Esempio n. 12
0
 void ForwardPacket(EventLoop netloop, Packet p)
 {
     //直接send
 }
Esempio n. 13
0
 public TcpListen(EventLoop loop) : base(loop)
 {
 }