| 48 | |
| 49 | #ifdef _WIN32 |
| 50 | struct WSAEvent |
| 51 | { |
| 52 | public: |
| 53 | WSAEvent(struct pollfd* fd) |
| 54 | : _fd(fd) |
| 55 | { |
| 56 | _event = WSACreateEvent(); |
| 57 | } |
| 58 | |
| 59 | WSAEvent(WSAEvent&& source) noexcept |
| 60 | { |
| 61 | _event = source._event; |
| 62 | source._event = WSA_INVALID_EVENT; // invalidate the event in the source |
| 63 | _fd = source._fd; |
| 64 | } |
| 65 | |
| 66 | ~WSAEvent() |
| 67 | { |
| 68 | if (_event != WSA_INVALID_EVENT) |
| 69 | { |
| 70 | // We must deselect the networkevents from the socket event. Otherwise the |
| 71 | // socket will report states that aren't there. |
| 72 | if (_fd != nullptr && (int)_fd->fd != -1) |
| 73 | WSAEventSelect(_fd->fd, _event, 0); |
| 74 | WSACloseEvent(_event); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | operator HANDLE() |
| 79 | { |
| 80 | return _event; |
| 81 | } |
| 82 | |
| 83 | operator struct pollfd*() |
| 84 | { |
| 85 | return _fd; |
| 86 | } |
| 87 | |
| 88 | private: |
| 89 | HANDLE _event; |
| 90 | struct pollfd* _fd; |
| 91 | }; |
| 92 | #endif |
| 93 | |
| 94 | // |