Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ithewei committed Dec 4, 2022
1 parent f8fe76f commit 5da4a32
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
19 changes: 14 additions & 5 deletions event/hloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
8 changes: 7 additions & 1 deletion evpp/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,13 @@ class SocketChannel : public Channel {
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);
Expand Down

0 comments on commit 5da4a32

Please sign in to comment.