Beispiel #1
0
        private void startSocketThread()
        {
            Ctrl.print("启动socket线程");

            if (ShineSetting.useKCP)
            {
                _kcpThread = new BaseThread("kcpThread");
                _kcpThread.setRunCall(kcpLoop);
                ThreadControl.addThread(_kcpThread);
                _kcpThread.start();
            }

            if (ShineSetting.socketUseAsync)
            {
                return;
            }

            _sendThread = new BaseThread("ioSendThread");
            _sendThread.setRunCall(sendLoop);
            ThreadControl.addThread(_sendThread);

            _receiveThread = new BaseThread("ioReceiveThread");
            _receiveThread.setRunCall(receiveLoop);
            _receiveThread.setSleepTime(1);
            ThreadControl.addThread(_receiveThread);

            _sendThread.start();
            _receiveThread.start();
        }
Beispiel #2
0
        /** 析构 */
        public void dispose()
        {
            closeAndClear();

            _disposed = true;

            if (ShineSetting.useKCP)
            {
                if (_kcpThread != null)
                {
                    _kcpThread.exit();
                    ThreadControl.removeThread(_kcpThread);
                    _kcpThread = null;
                }
            }


            if (!ShineSetting.socketUseAsync)
            {
                if (_sendThread != null)
                {
                    _sendThread.exit();
                    ThreadControl.removeThread(_sendThread);
                    _sendThread = null;
                }

                if (_receiveThread != null)
                {
                    _receiveThread.exit();
                    ThreadControl.removeThread(_receiveThread);
                    _receiveThread = null;
                }
            }
        }
Beispiel #3
0
        /** 初始化 */
        public static void init()
        {
            _mainThread = Thread.CurrentThread;

            _assistThread = new BaseThread("assistThread");
            _assistThread.start();
            addThread(_assistThread);

            _ioThread = new BaseThread("ioThread");
            _ioThread.start();
            addThread(_ioThread);
        }
Beispiel #4
0
 public static void removeThread(BaseThread thread)
 {
     _threadList.removeObj(thread);
 }
Beispiel #5
0
 public static void addThread(BaseThread thread)
 {
     _threadList.add(thread);
 }