Skip to content

Commit 8c9c421

Browse files
committed
Add TCP_NODELAY support
1 parent 04a4dce commit 8c9c421

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

clickhouse/base/socket.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ void SocketHolder::SetTcpKeepAlive(int idle, int intvl, int cnt) noexcept {
169169
#endif
170170
}
171171

172+
void SocketHolder::SetTcpNoDelay(bool nodelay) noexcept {
173+
int val = nodelay;
174+
setsockopt(handle_, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
175+
}
176+
172177
SocketHolder& SocketHolder::operator = (SocketHolder&& other) noexcept {
173178
if (this != &other) {
174179
Close();

clickhouse/base/socket.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class SocketHolder {
6262
/// before dropping the connection.
6363
void SetTcpKeepAlive(int idle, int intvl, int cnt) noexcept;
6464

65+
/// @params nodelay whether to enable TCP_NODELAY
66+
void SetTcpNoDelay(bool nodelay) noexcept;
67+
6568
SocketHolder& operator = (SocketHolder&& other) noexcept;
6669

6770
operator SOCKET () const noexcept;

clickhouse/client.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ void Client::Impl::ResetConnection() {
277277
options_.tcp_keepalive_intvl.count(),
278278
options_.tcp_keepalive_cnt);
279279
}
280+
if (options_.tcp_nodelay) {
281+
s.SetTcpNoDelay(options_.tcp_nodelay);
282+
}
280283

281284
socket_ = std::move(s);
282285
socket_input_ = SocketInput(socket_);

clickhouse/client.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ struct ClientOptions {
8080
DECLARE_FIELD(tcp_keepalive_intvl, std::chrono::seconds, SetTcpKeepAliveInterval, std::chrono::seconds(5));
8181
DECLARE_FIELD(tcp_keepalive_cnt, unsigned int, SetTcpKeepAliveCount, 3);
8282

83+
// TCP options
84+
DECLARE_FIELD(tcp_nodelay, bool, TcpNoDelay, false);
85+
8386
#undef DECLARE_FIELD
8487
};
8588

0 commit comments

Comments
 (0)