acceptor.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include "acceptor_status.h"
  3. #include "defs.h"
  4. #include "event_loop.h"
  5. #include "netaddr.h"
  6. #include "session_impl.h"
  7. #include "shutdown_state.h"
  8. #include <library/cpp/messagebus/actor/actor.h>
  9. #include <util/system/event.h>
  10. namespace NBus {
  11. namespace NPrivate {
  12. class TAcceptor
  13. : public NEventLoop::IEventHandler,
  14. private ::NActor::TActor<TAcceptor> {
  15. friend struct TBusSessionImpl;
  16. friend class ::NActor::TActor<TAcceptor>;
  17. public:
  18. TAcceptor(TBusSessionImpl* session, ui64 acceptorId, SOCKET socket, const TNetAddr& addr);
  19. void HandleEvent(SOCKET socket, void* cookie) override;
  20. void Shutdown();
  21. inline ::NActor::TActor<TAcceptor>* GetActor() {
  22. return this;
  23. }
  24. private:
  25. void SendStatus(TInstant now);
  26. void Act(::NActor::TDefaultTag);
  27. private:
  28. const ui64 AcceptorId;
  29. TBusSessionImpl* const Session;
  30. NEventLoop::TChannelPtr Channel;
  31. TAcceptorStatus Stats;
  32. TAtomicShutdownState ShutdownState;
  33. struct TGranStatus {
  34. TGranStatus(TDuration gran)
  35. : Listen(gran)
  36. {
  37. }
  38. TGranUp<TAcceptorStatus> Listen;
  39. };
  40. TGranStatus GranStatus;
  41. };
  42. }
  43. }