فهرست منبع

valgrind check

ithewei 4 سال پیش
والد
کامیت
d47447aec5
3فایلهای تغییر یافته به همراه25 افزوده شده و 5 حذف شده
  1. 3 5
      evpp/Channel.h
  2. 11 0
      examples/protorpc/protorpc_client.cpp
  3. 11 0
      examples/protorpc/protorpc_server.cpp

+ 3 - 5
evpp/Channel.h

@@ -71,7 +71,7 @@ public:
     }
 
     bool isOpened() {
-        if (io_ == NULL) return false;
+        if (io_ == NULL || status >= DISCONNECTED) return false;
         return id_ == hio_id(io_) && hio_is_opened(io_);
     }
     bool isClosed() {
@@ -135,13 +135,11 @@ public:
     uint32_t    id_;
     void*       ctx_;
     enum Status {
-        // Channel::Status
         OPENED,
-        CLOSED,
-        // SocketChannel::Status
         CONNECTING,
         CONNECTED,
         DISCONNECTED,
+        CLOSED,
     } status;
     std::function<void(Buffer*)> onread;
     std::function<void(Buffer*)> onwrite;
@@ -240,7 +238,7 @@ public:
     }
 
     bool isConnected() {
-        return isOpened() && status == CONNECTED;
+        return status == CONNECTED && isOpened();
     }
 
     std::string localaddr() {

+ 11 - 0
examples/protorpc/protorpc_client.cpp

@@ -19,6 +19,17 @@ using namespace hv;
 #include "generated/calc.pb.h"
 #include "generated/login.pb.h"
 
+// valgrind --leak-check=full --show-leak-kinds=all
+class ProtobufRAII {
+public:
+    ProtobufRAII() {
+    }
+    ~ProtobufRAII() {
+        google::protobuf::ShutdownProtobufLibrary();
+    }
+};
+static ProtobufRAII s_protobuf;
+
 namespace protorpc {
 typedef std::shared_ptr<protorpc::Request>  RequestPtr;
 typedef std::shared_ptr<protorpc::Response> ResponsePtr;

+ 11 - 0
examples/protorpc/protorpc_server.cpp

@@ -17,6 +17,17 @@ using namespace hv;
 #include "handler/calc.h"
 #include "handler/login.h"
 
+// valgrind --leak-check=full --show-leak-kinds=all
+class ProtobufRAII {
+public:
+    ProtobufRAII() {
+    }
+    ~ProtobufRAII() {
+        google::protobuf::ShutdownProtobufLibrary();
+    }
+};
+static ProtobufRAII s_protobuf;
+
 protorpc_router router[] = {
     {"add", calc_add},
     {"sub", calc_sub},