コード例 #1
0
ファイル: Ctrl.cs プロジェクト: shineTeam7/home3
        //io

        public static void printForIO(string str)
        {
            ThreadControl.addMainFunc(() =>
            {
                toLog(str, SLogType.Normal);
            });
        }
コード例 #2
0
ファイル: Ctrl.cs プロジェクト: shineTeam7/home3
 public static void printExceptionForIO(Exception e)
 {
     ThreadControl.addMainFunc(() =>
     {
         toLog(exceptionToString("", e), SLogType.Normal);
     });
 }
コード例 #3
0
ファイル: ShineSetup.cs プロジェクト: shineTeam7/home3
 /** 退出(入口) */
 public static void exit()
 {
     ThreadControl.addMainFunc(() =>
     {
         doExit();
     });
 }
コード例 #4
0
ファイル: ShineSetup.cs プロジェクト: shineTeam7/home3
 /** 关闭(主动调用)(主线程) */
 public static void exit(String str)
 {
     ThreadControl.addMainFunc(() =>
     {
         Ctrl.errorLog(str);
         doExit();
     });
 }
コード例 #5
0
ファイル: BaseSocketContent.cs プロジェクト: shineTeam7/home3
        private void onSocketConnect(IAsyncResult result)
        {
            bool isError = false;

            try
            {
                _socket.EndConnect(result);
            }
            catch (Exception e)
            {
                // Ctrl.printExceptionForIO(e);
                isError = true;
            }

            try
            {
                EndPoint localEndPoint = _socket.LocalEndPoint;

                if (localEndPoint != null)
                {
                    Ctrl.debugLogForIO("本地端口:", localEndPoint.Serialize().ToString(), doIndex);
                }
            }
            catch (Exception e)
            {
                Ctrl.printExceptionForIO(e);
            }

            Ctrl.debugLogForIO("socketContent连接结果,success:", !isError, this.GetHashCode());

            ThreadControl.addMainFunc(() =>
            {
                if (isError)
                {
                    connectFailedOnce();
                }
                else
                {
                    connectSuccess();
                }
            });
        }
コード例 #6
0
ファイル: Ctrl.cs プロジェクト: shineTeam7/home3
        /** 发送log */
        private static void toSendLog(int type, string str)
        {
            if (!ShineSetting.needLogSendServer || _logPause)
            {
                return;
            }

            if (str.Length > _sendLogMax)
            {
                str = str.Substring(0, _sendLogMax) + "...";
            }


            if (_sendLogFunc != null)
            {
                ThreadControl.addMainFunc(() =>
                {
                    _sendLogFunc(type, str);
                });
            }
        }
コード例 #7
0
ファイル: BaseSocketContent.cs プロジェクト: shineTeam7/home3
        /** 即将关闭(IO线程) */
        protected void preBeClose(int way)
        {
            // Ctrl.debugLogForIO("preBeClose",way);

            doClose();

            if (_clozed)
            {
                return;
            }

            _clozed = true;

            Ctrl.debugLogForIO("preBeClose2", way, this.GetHashCode());

            ThreadControl.addMainFunc(() =>
            {
                if (checkIsCurrent())
                {
                    _parent.beClose();
                }
            });
        }
コード例 #8
0
ファイル: Ctrl.cs プロジェクト: shineTeam7/home3
 public static void warnLogForIO(params object[] args)
 {
     ThreadControl.addMainFunc(() => { warnLog(args); });
 }
コード例 #9
0
ファイル: BaseSocket.cs プロジェクト: shineTeam7/home3
        private void toGetDNS()
        {
            _state       = Connecting;
            _connectTime = 0;

            int index = ++_doIndex;

            _currentInfo = _ipInfoDic.get(_host);

            if (_currentInfo != null)
            {
                preConnectAfterAddress();
            }
            else
            {
                IPAddress address;

                if (!IPAddress.TryParse(_host, out address))
                {
                    Ctrl.debugLog("dns上");

                    Dns.BeginGetHostAddresses(_host, v =>
                    {
                        IPAddress[] addresses = null;

                        try
                        {
                            addresses = Dns.EndGetHostAddresses(v);
                        }
                        catch (Exception e)
                        {
                            Ctrl.printExceptionForIO(e);
                        }

                        ThreadControl.addMainFunc(() =>
                        {
                            if (index == _doIndex)
                            {
                                if (addresses != null)
                                {
                                    foreach (IPAddress ipAddress in addresses)
                                    {
                                        Ctrl.print("dns看收到的上地址", ipAddress);
                                    }

                                    _currentInfo = registIPInfo(_host, addresses);
                                    preConnectAfterAddress();
                                }
                                else
                                {
                                    Ctrl.printForIO("解析dns失败");
                                }
                            }
                            else
                            {
                                Ctrl.print("dns获取完,已经到下个index");
                            }
                        });
                    }, null);
                }
                else
                {
                    Ctrl.debugLog("dns下");
                    _currentInfo = registIPInfo(_host, new[] { address });
                    preConnectAfterAddress();
                }
            }
        }
コード例 #10
0
ファイル: BaseSocket.cs プロジェクト: shineTeam7/home3
        /** 收到一个协议包(netIO线程) */
        private void onSocketDataT(byte[] data, int pos, int len)
        {
            _readStream.setBuf(data, pos, len);

            //客户端不需要检测

            int mid = _readStream.natureReadUnsignedShort();

            //检测序号
            if (!BytesControl.isIgnoreMessage(mid))
            {
                int receiveIndex = _readStream.natureReadShort();

                int nowIndex = _receiveMsgIndex;

                if (receiveIndex != nowIndex)
                {
                    ThreadControl.addMainFunc(() =>
                    {
                        Ctrl.warnLog("序号检测没对上," + " nowIndex:" + nowIndex + " receiveIndex:" + receiveIndex + " mid:" + mid);

                        //视为被动关闭
                        closeForIO(Close_Error);
                    });

                    return;
                }

                ++_receiveMsgIndex;
            }

            if (_createResponseFunc != null)
            {
                BaseResponse response = _createResponseFunc(mid);

                if (response == null)
                {
                    if (ShineSetting.needMessageExistCheck)
                    {
                        ThreadControl.addMainFunc(() =>
                        {
                            Ctrl.throwError("未解析mid为" + mid + "的协议");
                        });
                    }

                    return;
                }

                if (response.isNewOne)
                {
                    _newResponseNum++;
                }

                response.socket = this;

                BaseResponse response2 = response.readFromStream(_readStream);

                //变了
                if (response2 != response)
                {
                    //直接回收 IO
                    BytesControl.releaseResponse(response);
                }

                if (response2 != null)
                {
                    if (ShineSetting.messageUsePool && response2.needRelease())
                    {
                        _responseCacheQueue.offer(response2);
                    }

                    //入队
                    _receiveQueue.add(response2);
                }
            }
        }