Ejemplo n.º 1
0
        /// <summary>
        /// 지정시간동안 Client 요청이 없으면 강제 종료 처리
        /// </summary>
        private void AliveCheckSockets_ThreadEntry()
        {
            Dictionary <EndPoint, FACInfo> acceptedList;

            //bool isalive = true;
            while (true)
            {
                Thread.Sleep(1000 * 10);

                lock (FACContainer.LockThis)
                {
                    acceptedList = new Dictionary <EndPoint, FACInfo>(FACContainer.AcceptedList);
                }

                foreach (KeyValuePair <EndPoint, FACInfo> kvPair in acceptedList)
                {
                    try
                    {
                        FACInfo info = FACContainer.FindFACInfo(kvPair.Key);
                        if (info == null)
                        {
                            continue;
                        }

                        if (Config.SERVER_LIMIT_RESPONSE_TIME > 0 &&
                            DateTime.Now.Subtract(info.LastRequestTime).TotalSeconds > Config.SERVER_LIMIT_RESPONSE_TIME)
                        {
                            // 종료 처리
                            SocketListener.Log.WRN(string.Format("AliveCheckSockets_ThreadEntry() : Arrive timeout. {0}/{1}"
                                                                 , DateTime.Now.Subtract(info.LastRequestTime).TotalSeconds
                                                                 , Config.SERVER_LIMIT_RESPONSE_TIME));

                            // 이미 삭제 되었을때 Exception 발생
                            if (info.Socket != null)
                            {
                                SocketListener.Log.WRN(string.Format("{0}|Socket Disconnect.", kvPair.Key.ToString()));
                                try { info.Socket.Disconnect(false); }
                                catch { }
                            }

                            FACContainer.Remove(info.recvEventArgs);
                            FACContainer.AcceptedList.Remove(kvPair.Key);
                        }
                    }
                    catch (Exception ex)
                    {
                        SocketListener.Log.ERR(string.Format("{0}|AliveCheckSockets_ThreadEntry() {1}\r\n{2}", kvPair.Key.ToString(), ex.Message, ex.StackTrace));
                        continue;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Shutdown -> Close
        /// </summary>
        private bool CloseClientSocket(SocketAsyncEventArgs e)
        {
            try
            {
                SocketListener.Log.MSG(e, "Start Close FaxAgent.");
                DataHoldingUserToken receiveSendToken = e.UserToken as DataHoldingUserToken;
                if (receiveSendToken.dataToReceive != null)
                {
                    receiveSendToken.CreateNewDataHolder();
                }

                // 로그아웃 처리
                FACInfo facInfo = FACContainer.FindFACInfo(e);
                if (facInfo != null)
                {
                    // DB Logout 처리
                    if (FACContainer.LoginedList.Count > 0 && facInfo.USER_ID != "")
                    {
                        if (DbModule.Instance.FAS_LogoutAgentClient(facInfo.USER_ID) != Btfax.CommonLib.RESULT.SUCCESS)
                        {
                            SocketListener.Log.WRN(e, "Database Logout process failure");
                        }
                        else
                        {
                            SocketListener.Log.MSG(e, "Database Logout process success");
                        }
                    }
                }

                // socket close
                try     { e.AcceptSocket.Shutdown(SocketShutdown.Both); }
                catch { }

                if (e.AcceptSocket != null)
                {
                    try {
                        e.AcceptSocket.Close();
                        e.AcceptSocket = null;
                    }
                    catch { };
                }

                if (facInfo != null)
                {
                    this.poolOfRecvEventArgs.Push(facInfo.recvEventArgs);
                    this.poolOfSendEventArgs.Push(facInfo.sendEventArgs);
                }
                else
                {
                    this.CreateNewSaeaForRecvSendOne();
                    SocketListener.Log.MSG(string.Format("CreateNewSaeaForRecvSendOne this.poolOfRecvEventArgs:{0}, this.poolOfSendEventArgs.Push{1}"
                                                         , this.poolOfRecvEventArgs.Count
                                                         , this.poolOfSendEventArgs.Count));
                }

                FACContainer.Remove(e);

                // Accept count 감소
                Interlocked.Decrement(ref this.numberOfAcceptedSockets);
                this.theMaxConnectionsEnforcer.Release();

                SocketListener.Log.MSG(e, string.Format("Close FaxAgent success."));
                this.DisplayConnectionInfo();
                return(true);
            }
            catch (Exception ex)
            {
                // Accept count 감소
                Interlocked.Decrement(ref this.numberOfAcceptedSockets);
                this.theMaxConnectionsEnforcer.Release();

                SocketListener.Log.ERR(string.Format("CloseClientSocket : {0}\r\n{1}", ex.Message, ex.StackTrace));
                return(false);
            }
        }