@@ -59,21 +59,15 @@ constexpr int kConnectInProgress = EINPROGRESS;
5959
6060// Saves the current blocking state, sets non-blocking, and returns a RAII guard
6161// that restores the original state on destruction.
62- struct BlockingGuard {
63- databento::detail::Socket fd;
64- #ifdef _WIN32
65- // No state to save on Windows
66- #else
67- int original_flags;
68- #endif
69-
70- explicit BlockingGuard (databento::detail::Socket fd) : fd{fd} {
62+ class BlockingGuard {
63+ public:
64+ explicit BlockingGuard (databento::detail::Socket socket) : _fd{socket} {
7165#ifdef _WIN32
7266 unsigned long mode = 1 ;
7367 ::ioctlsocket (fd, FIONBIO, &mode);
7468#else
75- original_flags = ::fcntl (fd , F_GETFL, 0 );
76- ::fcntl (fd , F_SETFL, original_flags | O_NONBLOCK);
69+ _original_flags = ::fcntl (_fd , F_GETFL, 0 );
70+ ::fcntl (_fd , F_SETFL, _original_flags | O_NONBLOCK);
7771#endif
7872 }
7973
@@ -82,14 +76,22 @@ struct BlockingGuard {
8276 unsigned long mode = 0 ;
8377 ::ioctlsocket (fd, FIONBIO, &mode);
8478#else
85- ::fcntl (fd , F_SETFL, original_flags );
79+ ::fcntl (_fd , F_SETFL, _original_flags );
8680#endif
8781 }
8882
8983 BlockingGuard (const BlockingGuard&) = delete ;
9084 BlockingGuard& operator =(const BlockingGuard&) = delete ;
9185 BlockingGuard (BlockingGuard&&) = delete ;
9286 BlockingGuard& operator =(BlockingGuard&&) = delete ;
87+
88+ private:
89+ databento::detail::Socket _fd;
90+ #ifdef _WIN32
91+ // No state to save on Windows
92+ #else
93+ int _original_flags;
94+ #endif
9395};
9496} // namespace
9597
0 commit comments