You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "chenBright (via GitHub)" <gi...@apache.org> on 2023/02/01 12:09:24 UTC

[GitHub] [brpc] chenBright commented on a diff in pull request #2098: support TCP heartbeat of client

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


##########
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;

Review Comment:
   嗯,改过来了



-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org