MCPcopy Create free account
hub / github.com/Beckhoff/ADS / Select

Method Select

AdsLib/Sockets.cpp:203–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203bool Socket::Select(timeval *timeout) const
204{
205 /* prepare socket set for select() */
206 fd_set readSockets;
207 FD_ZERO(&readSockets);
208 FD_SET(m_Socket, &readSockets);
209
210 /* wait for receive data */
211 const int state = NATIVE_SELECT(m_Socket + 1, &readSockets, nullptr,
212 nullptr, timeout);
213 if (0 == state) {
214 LOG_ERROR("select() timeout");
215 throw TimeoutEx("select() timeout");
216 }
217
218 const auto lastError = WSAGetLastError();
219 if (lastError == WSAENOTSOCK) {
220 throw std::runtime_error("connection closed");
221 }
222
223 /* and check if socket was correct */
224 if ((1 != state) || (!FD_ISSET(m_Socket, &readSockets))) {
225 LOG_ERROR(
226 "something strange happen while waiting for socket in state: "
227 << state
228 << " with error: " << std::strerror(lastError));
229 return false;
230 }
231 return true;
232}
233
234size_t Socket::write(const Frame &frame) const
235{

Callers

nothing calls this directly

Calls 1

TimeoutExClass · 0.85

Tested by

no test coverage detected