cdjingit commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091428037


##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
     return 0;
 }
 
+void Socket::SetKeepalive(int fd) {
+    if (!_keepalive_options) {
+        return;
+    } else {
+        int keep_alive = 1;
+        socklen_t size = sizeof(keep_alive);
+        if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
+            LOG(FATAL) << "Fail to set keepalive of fd=" << fd;
+            return;
+        }
+    }
+
+#if defined(OS_LINUX)
+    if (_keepalive_options->keepalive_idle_s > 0) {
+        socklen_t size = sizeof(_keepalive_options->keepalive_idle_s);
+        if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE,
+            &_keepalive_options->keepalive_idle_s, size) < 0) {
+            LOG(FATAL) << "Fail to set keepidle of fd=" << fd;
+        }
+    }
+
+    if (_keepalive_options->keepalive_interval_s > 0) {
+        socklen_t size = sizeof(_keepalive_options->keepalive_interval_s);

Review Comment:
   size 变量可以不定义了,直接 
   ```
   ::setsockopt(fd, SOL_TCP, TCP_KEEPINTVL,
                         &_keepalive_options->keepalive_interval_s,
                        sizeof(_keepalive_options->keepalive_interval_s)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to