|
9 | 9 | #include <photon/net/socket.h> |
10 | 10 | #include <photon/thread/thread11.h> |
11 | 11 | #include <rdma/rsocket.h> |
| 12 | +#include <netinet/tcp.h> |
12 | 13 |
|
13 | 14 | #include <vector> |
14 | 15 |
|
@@ -38,6 +39,14 @@ struct RSockFD { |
38 | 39 | if (fd >= 0) { |
39 | 40 | rfcntl(fd, F_SETFL, O_NONBLOCK, 1); |
40 | 41 | } |
| 42 | + int optval; |
| 43 | + socklen_t optlen = sizeof(optlen); |
| 44 | + |
| 45 | + optval = 64; |
| 46 | + rsetsockopt(fd, SOL_RDMA, RDMA_INLINE, &optval, sizeof(optval)); |
| 47 | + optval = 1; |
| 48 | + rsetsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen); |
| 49 | + rsetsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &optval, optlen); |
41 | 50 | } |
42 | 51 | ~RSockFD() { |
43 | 52 | if (fd >= 0) { |
@@ -122,18 +131,16 @@ struct RSockFD { |
122 | 131 | ssize_t do_io_action(uint64_t t, FUNC f, ARGS... args) { |
123 | 132 | Timeout tmo(t); |
124 | 133 | do { |
125 | | - auto ret = do_poll(EVENT | POLLERR | POLLHUP, tmo.timeout()); |
126 | | - if (ret < 0) return ret; |
127 | | - if (ret & EVENT) { |
128 | | - auto x = f(fd, args...); |
129 | | - if (x < 0) { |
130 | | - ERRNO err; |
131 | | - if (err.no == EAGAIN || err.no == EWOULDBLOCK) { |
132 | | - continue; |
133 | | - } |
| 134 | + auto x = f(fd, args...); |
| 135 | + if (x < 0) { |
| 136 | + ERRNO err; |
| 137 | + if (err.no == EAGAIN || err.no == EWOULDBLOCK) { |
| 138 | + auto ret = do_poll(EVENT | POLLERR | POLLHUP, tmo.timeout()); |
| 139 | + if (ret < 0) return ret; |
| 140 | + continue; |
134 | 141 | } |
135 | | - return x; |
136 | 142 | } |
| 143 | + return x; |
137 | 144 | } while (tmo.timeout()); |
138 | 145 | return 0; |
139 | 146 | } |
|
0 commit comments