Skip to content

Commit ca1ec0b

Browse files
committed
net: split out poll and select variants from Sock::Wait()
1 parent 7cffc0b commit ca1ec0b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/util/sock.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ bool Sock::IsSelectable() const
143143
bool Sock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
144144
{
145145
#ifdef USE_POLL
146+
return WaitPoll(timeout, requested, occurred);
147+
#else
148+
return WaitSelect(timeout, requested, occurred);
149+
#endif /* USE_POLL */
150+
}
151+
152+
#ifdef USE_POLL
153+
bool Sock::WaitPoll(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
154+
{
146155
pollfd fd;
147156
fd.fd = m_socket;
148157
fd.events = 0;
@@ -171,7 +180,11 @@ bool Sock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occur
171180
}
172181

173182
return true;
174-
#else
183+
}
184+
#endif /* USE_POLL */
185+
186+
bool Sock::WaitSelect(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
187+
{
175188
if (!IsSelectable()) {
176189
return false;
177190
}
@@ -213,7 +226,6 @@ bool Sock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occur
213226
}
214227

215228
return true;
216-
#endif /* USE_POLL */
217229
}
218230

219231
void Sock::SendComplete(const std::string& data,

src/util/sock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ class Sock
221221
[[nodiscard]] virtual bool Wait(std::chrono::milliseconds timeout,
222222
Event requested,
223223
Event* occurred = nullptr) const;
224+
#ifdef USE_POLL
225+
bool WaitPoll(std::chrono::milliseconds timeout, Event requested, Event* occurred = nullptr) const;
226+
#endif /* USE_POLL */
227+
bool WaitSelect(std::chrono::milliseconds timeout, Event requested, Event* occurred = nullptr) const;
224228

225229
/* Higher level, convenience, methods. These may throw. */
226230

0 commit comments

Comments
 (0)