poller.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <util/generic/ptr.h>
  3. #include <util/generic/vector.h>
  4. #include <util/network/socket.h>
  5. #include <util/network/pollerimpl.h>
  6. #include <util/datetime/base.h>
  7. enum class EContPoller {
  8. Default /* "default" */,
  9. Select /* "select" */,
  10. Poll /* "poll" */,
  11. Epoll /* "epoll" */,
  12. Kqueue /* "kqueue" */
  13. };
  14. class IPollerFace {
  15. public:
  16. struct TChange {
  17. SOCKET Fd;
  18. void* Data;
  19. ui16 Flags;
  20. };
  21. struct TEvent {
  22. void* Data;
  23. int Status;
  24. ui16 Filter;
  25. };
  26. using TEvents = TVector<TEvent>;
  27. virtual ~IPollerFace() {
  28. }
  29. void Set(void* ptr, SOCKET fd, ui16 flags) {
  30. const TChange c = {fd, ptr, flags};
  31. Set(c);
  32. }
  33. virtual void Set(const TChange& change) = 0;
  34. virtual void Wait(TEvents& events, TInstant deadLine) = 0;
  35. virtual EContPoller PollEngine() const = 0;
  36. static THolder<IPollerFace> Default();
  37. static THolder<IPollerFace> Construct(TStringBuf name);
  38. static THolder<IPollerFace> Construct(EContPoller poller);
  39. };