Skip to content

Commit

Permalink
Merge pull request #54 from oraoto/nodelay
Browse files Browse the repository at this point in the history
Add TCP_NODELAY option
  • Loading branch information
Enmk authored Jan 9, 2021
2 parents 9d8b99d + eb5971f commit 3255b18
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
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 @@ -304,6 +304,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

0 comments on commit 3255b18

Please sign in to comment.