private void CreateNewSaeaForRecvSendOne() { Int32 tokenId; SocketAsyncEventArgs recvSAEAObjectForPool; SocketAsyncEventArgs sendSAEAObjectForPool; recvSAEAObjectForPool = new SocketAsyncEventArgs(); sendSAEAObjectForPool = new SocketAsyncEventArgs(); this.theBufferManager.SetBuffer(recvSAEAObjectForPool, sendSAEAObjectForPool); recvSAEAObjectForPool.Completed += new EventHandler <SocketAsyncEventArgs>(IO_Completed); sendSAEAObjectForPool.Completed += new EventHandler <SocketAsyncEventArgs>(IO_Completed); poolOfSendEventArgs.AssignTokenId(); tokenId = poolOfRecvEventArgs.AssignTokenId() + 1000000; DataHoldingUserToken theTempRecvUserToken = new DataHoldingUserToken(recvSAEAObjectForPool, recvSAEAObjectForPool.Offset, sendSAEAObjectForPool.Offset, this.socketListenerSettings.ReceivePrefixLength, this.socketListenerSettings.SendPrefixLength, tokenId); theTempRecvUserToken.CreateNewDataHolder(); recvSAEAObjectForPool.UserToken = theTempRecvUserToken; sendSAEAObjectForPool.UserToken = theTempRecvUserToken; this.poolOfRecvEventArgs.Push(recvSAEAObjectForPool); this.poolOfSendEventArgs.Push(sendSAEAObjectForPool); }
private void SendMessage(SocketAsyncEventArgs sendEventArgs) { DataHoldingUserToken sendToken = (DataHoldingUserToken)sendEventArgs.UserToken; sendToken.sendBytesRemainingCount = sendToken.dataToSend.Length; sendToken.bytesSentAlreadyCount = 0; sendToken.CreateNewDataHolder(); sendToken.Reset(); this.StartSend(sendEventArgs); }
/// <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); } }