协议定义与实现, 协议支持 批处理、特殊字符如\r\n\0。与单条命令测试。

/**
 * Header: 	| magic(4) | payloadLen(4) |
 *
 * Request
 * Payload: | opcount(4) | repeat Cmd |
 * Cmd: 	| OP(1) | argc(4) | repeat Arg |
 * Arg:		| arglen(4) | arg |
 *
 * Response
 * Payload: | opcount(4) | repeat Rsp |
 * Rsp:		| OP(1) | status(1) | datalen(4) | data |
 */

 kvstore层,先解析,再执行,最后构建返回体。
 一个是半包问题,没有处理。
 另一个是感觉协议结构有点麻烦,
This commit is contained in:
2026-01-05 23:20:37 +08:00
parent 7524c57442
commit 0dc86f5aa5
10 changed files with 890 additions and 9 deletions

View File

@@ -10,15 +10,20 @@
#include <stdlib.h>
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#define NETWORK_REACTOR 0
#define NETWORK_PROACTOR 1
#define NETWORK_NTYCO 2
#define NETWORK_SELECT NETWORK_PROACTOR
#define NETWORK_SELECT NETWORK_REACTOR
// 8MB
#define MAX_PAYLOAD_LEN 8388608
#define MAX_OPCOUNT 1024
// 4MB
#define MAX_ARG_LEN 4194304
#define KVS_MAX_TOKENS 128
@@ -26,6 +31,8 @@
#define ENABLE_RBTREE 1
#define ENABLE_HASH 1
#define NEW_KVSTORE 1
typedef int (*msg_handler)(char *msg, int length, char *response);