Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clickhouse/base/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ void SocketHolder::SetTcpKeepAlive(int idle, int intvl, int cnt) noexcept {
#endif
}

void SocketHolder::SetTcpNoDelay(bool nodelay) noexcept {
int val = nodelay;
setsockopt(handle_, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
}

SocketHolder& SocketHolder::operator = (SocketHolder&& other) noexcept {
if (this != &other) {
Close();
Expand Down
3 changes: 3 additions & 0 deletions clickhouse/base/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class SocketHolder {
/// before dropping the connection.
void SetTcpKeepAlive(int idle, int intvl, int cnt) noexcept;

/// @params nodelay whether to enable TCP_NODELAY
void SetTcpNoDelay(bool nodelay) noexcept;

SocketHolder& operator = (SocketHolder&& other) noexcept;

operator SOCKET () const noexcept;
Expand Down
3 changes: 3 additions & 0 deletions clickhouse/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ void Client::Impl::ResetConnection() {
options_.tcp_keepalive_intvl.count(),
options_.tcp_keepalive_cnt);
}
if (options_.tcp_nodelay) {
s.SetTcpNoDelay(options_.tcp_nodelay);
}

socket_ = std::move(s);
socket_input_ = SocketInput(socket_);
Expand Down
3 changes: 3 additions & 0 deletions clickhouse/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ struct ClientOptions {
DECLARE_FIELD(tcp_keepalive_intvl, std::chrono::seconds, SetTcpKeepAliveInterval, std::chrono::seconds(5));
DECLARE_FIELD(tcp_keepalive_cnt, unsigned int, SetTcpKeepAliveCount, 3);

// TCP options
DECLARE_FIELD(tcp_nodelay, bool, TcpNoDelay, true);

#undef DECLARE_FIELD
};

Expand Down