/* * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version. * Copyright (C) 2008-2016 TrinityCore * Copyright (C) 2005-2009 MaNGOS */ #ifndef __REALMACCEPTOR_H__ #define __REALMACCEPTOR_H__ #include #include #include "RealmSocket.h" #include "AuthSocket.h" class RealmAcceptor : public ACE_Acceptor { public: RealmAcceptor() = default; virtual ~RealmAcceptor() { if (reactor()) reactor()->cancel_timer(this, 1); } protected: virtual int make_svc_handler(RealmSocket*& sh) { if (sh == nullptr) ACE_NEW_RETURN(sh, RealmSocket, -1); sh->reactor(reactor()); sh->set_session(new AuthSocket(*sh)); return 0; } virtual int handle_timeout(const ACE_Time_Value& /*current_time*/, const void* /*act = 0*/) { LOG_INFO("server", "Resuming acceptor"); reactor()->cancel_timer(this, 1); return reactor()->register_handler(this, ACE_Event_Handler::ACCEPT_MASK); } virtual int handle_accept_error() { #if defined(ENFILE) && defined(EMFILE) if (errno == ENFILE || errno == EMFILE) { LOG_ERROR("server", "Out of file descriptors, suspending incoming connections for 10 seconds"); reactor()->remove_handler(this, ACE_Event_Handler::ACCEPT_MASK | ACE_Event_Handler::DONT_CALL); reactor()->schedule_timer(this, nullptr, ACE_Time_Value(10)); } #endif return 0; } }; #endif