@@ -101,20 +101,22 @@ SSL_CTX* CreateSslServerCntx() {
101
101
}
102
102
#endif
103
103
104
- bool ConfigureKeepAlive (int fd, unsigned interval_sec) {
105
- DCHECK_GT (interval_sec, 3u );
104
+ uint32_t tcp_keepalive;
105
+
106
+ bool ConfigureKeepAlive (int fd) {
107
+ DCHECK_GT (tcp_keepalive, 3u );
106
108
int val = 1 ;
107
109
if (setsockopt (fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof (val)) < 0 )
108
110
return false ;
109
111
110
- val = interval_sec ;
112
+ val = tcp_keepalive ;
111
113
if (setsockopt (fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof (val)) < 0 )
112
114
return false ;
113
115
114
116
/* Send next probes after the specified interval. Note that we set the
115
117
* delay as interval / 3, as we send three probes before detecting
116
118
* an error (see the next setsockopt call). */
117
- val = interval_sec / 3 ;
119
+ val = tcp_keepalive / 3 ;
118
120
if (setsockopt (fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof (val)) < 0 )
119
121
return false ;
120
122
@@ -141,21 +143,17 @@ Listener::Listener(Protocol protocol, ServiceInterface* si) : service_(si), prot
141
143
http_base_->set_resource_prefix (" http://static.dragonflydb.io/data-plane" );
142
144
si->ConfigureHttpHandlers (http_base_.get ());
143
145
144
- constexpr string_view kTcpFlagError = " tcp_keepalive expected to be greated than 3 seconds" ;
145
- tcp_keepalive_ = absl::GetFlag (FLAGS_tcp_keepalive);
146
- CHECK_GT (tcp_keepalive_, 3u ) << kTcpFlagError ;
147
- dfly::config_registry.Register (" tcp_keepalive" , [this ](const absl::CommandLineFlag& flag) {
148
- auto res = flag.TryGet <uint32_t >();
149
- if (!res)
150
- return false ;
151
-
152
- if (*res <= 3 ) {
153
- LOG (ERROR) << kTcpFlagError ;
154
- return false ;
155
- }
156
- tcp_keepalive_ = *res;
157
- return true ;
158
- });
146
+ tcp_keepalive = absl::GetFlag (FLAGS_tcp_keepalive);
147
+ CHECK_GT (tcp_keepalive, 3u ) << FLAGS_tcp_keepalive.Name () << " " << FLAGS_tcp_keepalive.Help ();
148
+ }
149
+
150
+ bool Listener::SetTcpKeepalive (uint32_t val) {
151
+ if (val <= 3 ) {
152
+ LOG (ERROR) << FLAGS_tcp_keepalive.Name () << " " << FLAGS_tcp_keepalive.Help ();
153
+ return false ;
154
+ }
155
+ tcp_keepalive = val;
156
+ return true ;
159
157
}
160
158
161
159
Listener::~Listener () {
@@ -175,7 +173,7 @@ error_code Listener::ConfigureServerSocket(int fd) {
175
173
LOG (WARNING) << " Could not set reuse addr on socket " << SafeErrorMessage (errno);
176
174
}
177
175
178
- bool success = ConfigureKeepAlive (fd, tcp_keepalive_ );
176
+ bool success = ConfigureKeepAlive (fd);
179
177
180
178
if (!success) {
181
179
int myerr = errno;
0 commit comments