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


##########
src/brpc/socket.h:
##########
@@ -198,6 +212,31 @@ struct SocketOptions {
     std::shared_ptr<AppConnect> app_connect;
     // The created socket will set parsing_context with this value.
     Destroyable* initial_parsing_context;
+
+    // Socket keepalive related options.
+    // Refer to `SocketKeepaliveOptions' for details
+    void enable_keepalive() {
+        if (!_keepalive_options) {
+            _keepalive_options.reset(new SocketKeepaliveOptions);
+        }
+    }
+    bool has_keepalive_options() { return _keepalive_options != NULL; }
+    const SocketKeepaliveOptions& keepalive_options() const {
+        return *_keepalive_options;
+    }
+    SocketKeepaliveOptions* mutable_keepalive_options() {
+        enable_keepalive();
+        return _keepalive_options.get();
+    }
+    std::shared_ptr<SocketKeepaliveOptions>
+    shared_keepalibe_options() const {
+        return _keepalive_options;
+    }
+
+private:
+    // SocketKeepaliveOptions is not often used, allocate it on heap to
+    // prevent SocketKeepaliveOptions from being bloated in most cases.
+    std::shared_ptr<SocketKeepaliveOptions> _keepalive_options;

Review Comment:
   可以改成public,不过使用SocketOptions就麻烦一点,需要new SocketKeepaliveOptions或者make_shared。



##########
src/brpc/socket.h:
##########
@@ -198,6 +212,31 @@ struct SocketOptions {
     std::shared_ptr<AppConnect> app_connect;
     // The created socket will set parsing_context with this value.
     Destroyable* initial_parsing_context;
+
+    // Socket keepalive related options.
+    // Refer to `SocketKeepaliveOptions' for details
+    void enable_keepalive() {
+        if (!_keepalive_options) {
+            _keepalive_options.reset(new SocketKeepaliveOptions);
+        }
+    }
+    bool has_keepalive_options() { return _keepalive_options != NULL; }
+    const SocketKeepaliveOptions& keepalive_options() const {
+        return *_keepalive_options;
+    }
+    SocketKeepaliveOptions* mutable_keepalive_options() {
+        enable_keepalive();
+        return _keepalive_options.get();
+    }
+    std::shared_ptr<SocketKeepaliveOptions>
+    shared_keepalibe_options() const {
+        return _keepalive_options;
+    }
+
+private:
+    // SocketKeepaliveOptions is not often used, allocate it on heap to
+    // prevent SocketKeepaliveOptions from being bloated in most cases.
+    std::shared_ptr<SocketKeepaliveOptions> _keepalive_options;

Review Comment:
   done



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