poller.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "socket.h"
  3. #include <util/generic/ptr.h>
  4. #include <util/datetime/base.h>
  5. class TSocketPoller {
  6. public:
  7. TSocketPoller();
  8. ~TSocketPoller();
  9. void WaitRead(SOCKET sock, void* cookie);
  10. void WaitWrite(SOCKET sock, void* cookie);
  11. void WaitReadWrite(SOCKET sock, void* cookie);
  12. void WaitRdhup(SOCKET sock, void* cookie);
  13. void WaitReadOneShot(SOCKET sock, void* cookie);
  14. void WaitWriteOneShot(SOCKET sock, void* cookie);
  15. void WaitReadWriteOneShot(SOCKET sock, void* cookie);
  16. void WaitReadWriteEdgeTriggered(SOCKET sock, void* cookie);
  17. void RestartReadWriteEdgeTriggered(SOCKET sock, void* cookie, bool empty = true);
  18. void Unwait(SOCKET sock);
  19. size_t WaitD(void** events, size_t len, const TInstant& deadLine);
  20. inline size_t WaitT(void** events, size_t len, const TDuration& timeOut) {
  21. return WaitD(events, len, timeOut.ToDeadLine());
  22. }
  23. inline size_t WaitI(void** events, size_t len) {
  24. return WaitD(events, len, TInstant::Max());
  25. }
  26. inline void* WaitD(const TInstant& deadLine) {
  27. void* ret;
  28. if (WaitD(&ret, 1, deadLine)) {
  29. return ret;
  30. }
  31. return nullptr;
  32. }
  33. inline void* WaitT(const TDuration& timeOut) {
  34. return WaitD(timeOut.ToDeadLine());
  35. }
  36. inline void* WaitI() {
  37. return WaitD(TInstant::Max());
  38. }
  39. private:
  40. class TImpl;
  41. THolder<TImpl> Impl_;
  42. };