PageRenderTime 67ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/server/game/Server/WorldSocketAcceptor.h

http://github.com/SingularityCore/Singularity
C Header | 68 lines | 36 code | 10 blank | 22 comment | 6 complexity | 1e6c1a5fa3687b450bd75c6fd1c2f574 MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0, BSD-3-Clause
  1. /*
  2. * Copyright (C) 2011 SingularityCore <http://www.singularitycore.org/>
  3. * Copyright (C) 2008-2011 TrinityCore <http://www.trinitycore.org/>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /** \addtogroup u2w User to World Communication
  19. * @{
  20. * \file WorldSocketMgr.h
  21. */
  22. #ifndef __WORLDSOCKETACCEPTOR_H_
  23. #define __WORLDSOCKETACCEPTOR_H_
  24. #include "Common.h"
  25. #include <ace/Acceptor.h>
  26. #include <ace/SOCK_Acceptor.h>
  27. #include "WorldSocket.h"
  28. class WorldSocketAcceptor : public ACE_Acceptor<WorldSocket, ACE_SOCK_Acceptor>
  29. {
  30. public:
  31. WorldSocketAcceptor(void) { }
  32. virtual ~WorldSocketAcceptor(void)
  33. {
  34. if (reactor())
  35. reactor()->cancel_timer(this, 1);
  36. }
  37. protected:
  38. virtual int handle_timeout(const ACE_Time_Value& /*current_time*/, const void* /*act = 0*/)
  39. {
  40. sLog->outBasic("Resuming acceptor");
  41. reactor()->cancel_timer(this, 1);
  42. return reactor()->register_handler(this, ACE_Event_Handler::ACCEPT_MASK);
  43. }
  44. virtual int handle_accept_error(void)
  45. {
  46. #if defined(ENFILE) && defined(EMFILE)
  47. if (errno == ENFILE || errno == EMFILE)
  48. {
  49. sLog->outError("Out of file descriptors, suspending incoming connections for 10 seconds");
  50. reactor()->remove_handler(this, ACE_Event_Handler::ACCEPT_MASK | ACE_Event_Handler::DONT_CALL);
  51. reactor()->schedule_timer(this, NULL, ACE_Time_Value(10));
  52. }
  53. #endif
  54. return 0;
  55. }
  56. };
  57. #endif /* __WORLDSOCKETACCEPTOR_H_ */
  58. /// @}