public int GetSessionCount() { if (m_SessionGroup == null) { return(0); } else { return(m_SessionGroup.GetSessionCount()); } }
public void AcceptCallback(IAsyncResult ar) { // Signal the main thread to continue. Socket socket = null; lock (m_ListenWatcher) { try { // Get the socket that handles the client request. Socket listener = (Socket)ar.AsyncState; if (listener != null) { socket = listener.EndAccept(ar); } } catch { } } // after unlock the watcher, re-activate it ... m_ListenWatcher.Set(); if (socket == null) { return; } if (!m_Acceptable || m_State <= 0) { try { socket.Close(); } catch { } return; } if (m_MaxClientCount > 0 && m_SessionGroup.GetSessionCount() >= m_MaxClientCount) { try { socket.Close(); } catch { } return; } // set every new session's io buffer size to a global value by default // but you still can change it in every session's OnConnect event function socket.ReceiveBufferSize = m_IoBufferSize; socket.SendBufferSize = m_IoBufferSize; // Create the session object. Session session = null; lock (m_SessionGroup) { m_NextSessionID++; session = new Session(m_NextSessionID, socket, m_IoHandler, m_IoFilter, m_Cert != null); session.SetSessionGroup(m_SessionGroup); } if (session != null) { Stream stream = session.GetStream(); if (stream != null) { if (stream is SslStream && m_Cert != null) { (stream as SslStream).BeginAuthenticateAsServer(m_Cert, new AsyncCallback(AuthenticateCallback), session); } else if (stream is NetworkStream) { if (session != null) { session.Open(); } } } } }