public SessionBase CreateSession(Socket socket) { //Logger.Debug("CreateSession TryPopRecvSAEA Count {0}", m_managerSAEA.PopRecvSAEACount); SocketAsyncEventArgs recvSAEA; if (false == m_managerSAEA.TryPopRecvSAEA(out recvSAEA)) { Task.Run(() => { socket.CloseEx(); }); // 로그 //Logger.Error("Failed CreateSession TryPopRecvSAEA"); return(null); } SocketAsyncEventArgs sendSAEA; if (false == m_managerSAEA.TryPopSendSAEA(out sendSAEA)) { m_managerSAEA.PushRecvSAEA(recvSAEA); Task.Run(() => { socket.CloseEx(); }); // 로그 //Logger.Error("Failed CreateSession TryPopSendSAEA"); return(null); } SessionBase session = new Session(socket, recvSAEA, sendSAEA, m_managerSAEA.m_pooledBufferManager); if (null == session) { recvSAEA.UserToken = null; sendSAEA.UserToken = null; m_managerSAEA.PushRecvSAEA(recvSAEA); m_managerSAEA.PushSendSAEA(sendSAEA); Task.Run(() => { socket.CloseEx(); }); //Logger.Error("Failed new Session"); return(null); } long managedNumber = m_keyGenerator.Alloc(); session.SetNumber(managedNumber, Environment.TickCount); //if (false == m_managerSession.TryAdd(session)) // return null; if (null != m_fnAddSession) { m_fnAddSession(session); } return(session); }
public SessionBase CreateSession(Socket socket) { SocketAsyncEventArgs recvSAEA; if (!m_managerSAEA.TryPopRecvSAEA(out recvSAEA)) { Task.Run(() => { socket.CloseEx(); }); // 로그 return(null); } SocketAsyncEventArgs sendSAEA; if (!m_managerSAEA.TryPopSendSAEA(out sendSAEA)) { m_managerSAEA.PushRecvSAEA(recvSAEA); Task.Run(() => { socket.CloseEx(); }); // 로그 return(null); } ClientSession session = new ClientSession(socket, recvSAEA, sendSAEA, m_managerSAEA.m_pooledBufferManager); if (null == session) { recvSAEA.UserToken = null; sendSAEA.UserToken = null; m_managerSAEA.PushRecvSAEA(recvSAEA); m_managerSAEA.PushSendSAEA(sendSAEA); Task.Run(() => { socket.CloseEx(); }); return(null); } long managedNumber = m_keyGenerator.Alloc(); session.SetNumber(managedNumber, Environment.TickCount); //m_managerSession.Add(session); if (null != m_fnAddSession) { m_fnAddSession(session); } return(session); }