Răsfoiți Sursa

Add some comments

ithewei 3 ani în urmă
părinte
comite
5da4a32a15
4 a modificat fișierele cu 25 adăugiri și 6 ștergeri
  1. 2 0
      README-CN.md
  2. 2 0
      README.md
  3. 14 5
      event/hloop.h
  4. 7 1
      evpp/Channel.h

+ 2 - 0
README-CN.md

@@ -387,6 +387,7 @@ int main(int argc, char** argv) {
 
 ### c版本
 - 事件循环:     [examples/hloop_test.c](examples/hloop_test.c)
+- 定时器:       [examples/htimer_test.c](examples/htimer_test.c)
 - TCP回显服务:  [examples/tcp_echo_server.c](examples/tcp_echo_server.c)
 - TCP聊天服务:  [examples/tcp_chat_server.c](examples/tcp_chat_server.c)
 - TCP代理服务:  [examples/tcp_proxy_server.c](examples/tcp_proxy_server.c)
@@ -405,6 +406,7 @@ int main(int argc, char** argv) {
 - 事件循环: [evpp/EventLoop_test.cpp](evpp/EventLoop_test.cpp)
 - 事件循环线程: [evpp/EventLoopThread_test.cpp](evpp/EventLoopThread_test.cpp)
 - 事件循环线程池: [evpp/EventLoopThreadPool_test.cpp](evpp/EventLoopThreadPool_test.cpp)
+- 定时器:    [evpp/TimerThread_test.cpp](evpp/TimerThread_test.cpp)
 - TCP服务端: [evpp/TcpServer_test.cpp](evpp/TcpServer_test.cpp)
 - TCP客户端: [evpp/TcpClient_test.cpp](evpp/TcpClient_test.cpp)
 - UDP服务端: [evpp/UdpServer_test.cpp](evpp/UdpServer_test.cpp)

+ 2 - 0
README.md

@@ -334,6 +334,7 @@ int main(int argc, char** argv) {
 ## 🍭 More examples
 ### c version
 - [examples/hloop_test.c](examples/hloop_test.c)
+- [examples/htimer_test.c](examples/htimer_test.c)
 - [examples/tcp_echo_server.c](examples/tcp_echo_server.c)
 - [examples/tcp_chat_server.c](examples/tcp_chat_server.c)
 - [examples/tcp_proxy_server.c](examples/tcp_proxy_server.c)
@@ -352,6 +353,7 @@ int main(int argc, char** argv) {
 - [evpp/EventLoop_test.cpp](evpp/EventLoop_test.cpp)
 - [evpp/EventLoopThread_test.cpp](evpp/EventLoopThread_test.cpp)
 - [evpp/EventLoopThreadPool_test.cpp](evpp/EventLoopThreadPool_test.cpp)
+- [evpp/TimerThread_test.cpp](evpp/TimerThread_test.cpp)
 - [evpp/TcpServer_test.cpp](evpp/TcpServer_test.cpp)
 - [evpp/TcpClient_test.cpp](evpp/TcpClient_test.cpp)
 - [evpp/UdpServer_test.cpp](evpp/UdpServer_test.cpp)

+ 14 - 5
event/hloop.h

@@ -494,17 +494,20 @@ typedef struct unpack_setting_s {
             unsigned char   delimiter[PACKAGE_MAX_DELIMITER_BYTES];
             unsigned short  delimiter_bytes;
         };
-        // UNPACK_BY_LENGTH_FIELD
-        /* package_len = head_len + body_len + length_adjustment
+        /*
+         * UNPACK_BY_LENGTH_FIELD
+         *
+         * package_len = head_len + body_len + length_adjustment
          *
          * if (length_field_coding == ENCODE_BY_VARINT) head_len = body_offset + varint_bytes - length_field_bytes;
          * else head_len = body_offset;
          *
-         * body_len calc by length_field
+         * length_field stores body length, exclude head length,
+         * if length_field = head_len + body_len, then length_adjustment should be set to -head_len.
          *
          */
         struct {
-            unsigned short  body_offset;
+            unsigned short  body_offset; // Equal to head length usually
             unsigned short  length_field_offset;
             unsigned short  length_field_bytes;
                      short  length_adjustment;
@@ -528,7 +531,13 @@ typedef struct unpack_setting_s {
 #endif
 } unpack_setting_t;
 
-// @see examples/jsonrpc examples/protorpc
+/*
+ * @see examples/jsonrpc examples/protorpc
+ *
+ * NOTE: unpack_setting_t of multiple IOs of the same function also are same,
+ *       so only the pointer of unpack_setting_t is stored in hio_t,
+ *       the life time and of unpack_setting_t shoud be guaranteed by caller.
+ */
 HV_EXPORT void hio_set_unpack(hio_t* io, unpack_setting_t* setting);
 HV_EXPORT void hio_unset_unpack(hio_t* io);
 

+ 7 - 1
evpp/Channel.h

@@ -290,7 +290,13 @@ public:
         hio_set_heartbeat(io_, interval_ms, send_heartbeat);
     }
 
-    // unpack
+    /*
+     * unpack
+     *
+     * NOTE: unpack_setting_t of multiple IOs of the same function also are same,
+     *       so only the pointer of unpack_setting_t is stored in hio_t,
+     *       the life time and of unpack_setting_t shoud be guaranteed by caller.
+     */
     void setUnpack(unpack_setting_t* setting) {
         if (io_ == NULL) return;
         hio_set_unpack(io_, setting);