simple-socket library 1.5.0
Loading...
Searching...
No Matches
TempFailure-timeout.hh
1#ifndef NET_TempFailure_h__
2#define NET_TempFailure_h__
3
4#include <unistd.h>
5#include <errno.h>
6
7#ifndef TEMP_FAILURE_RETRY
8#define TEMP_FAILURE_RETRY(expression) (expression)
9#endif
10
11#endif // NET_TempFailure_h__
12
13
14/*
15 const auto deadline =
16 std::chrono::steady_clock::now() +
17 std::chrono::milliseconds(timeout);
18
19 for (;;)
20 {
21 const auto now = std::chrono::steady_clock::now();
22
23 if (now >= deadline)
24 {
25 // Abort outstanding connection here.
26 // More on this below.
27
28 restoreFlags();
29 errno = ETIMEDOUT;
30 return 0;
31 }
32
33 const auto remaining =
34 std::chrono::duration_cast<std::chrono::milliseconds>(
35 deadline - now);
36
37 pollfd pfd{};
38 pfd.fd = m_socket;
39 pfd.events = POLLOUT;
40
41 const int pollResult =
42 ::poll(&pfd, 1, static_cast<int>(remaining.count()));
43
44 if (pollResult < 0)
45 {
46 if (errno == EINTR)
47 continue;
48
49 const int savedErrno = errno;
50 restoreFlags();
51 errno = savedErrno;
52 throw SocketException("timedConnect failed (poll)");
53 }
54
55 if (pollResult == 0)
56 continue; // deadline check at top
57*/