Skip to content

Commit c96e17b

Browse files
committed
Make rsocket less latency
1 parent ceccc37 commit c96e17b

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

net/rsocket/rsocket.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <photon/net/socket.h>
1010
#include <photon/thread/thread11.h>
1111
#include <rdma/rsocket.h>
12+
#include <netinet/tcp.h>
1213

1314
#include <vector>
1415

@@ -38,6 +39,14 @@ struct RSockFD {
3839
if (fd >= 0) {
3940
rfcntl(fd, F_SETFL, O_NONBLOCK, 1);
4041
}
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);
4150
}
4251
~RSockFD() {
4352
if (fd >= 0) {
@@ -122,18 +131,16 @@ struct RSockFD {
122131
ssize_t do_io_action(uint64_t t, FUNC f, ARGS... args) {
123132
Timeout tmo(t);
124133
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;
134141
}
135-
return x;
136142
}
143+
return x;
137144
} while (tmo.timeout());
138145
return 0;
139146
}

0 commit comments

Comments
 (0)