bugfix: reactor网络模型的的半包解析错误问题。
全量持久化时清除增量持久化的记录。
This commit is contained in:
@@ -14,8 +14,9 @@
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#define CMD_SIZE (4096)
|
||||
#define CMD_SIZE (1024)
|
||||
#define BATCH_SIZE (65536)
|
||||
#define KVS_BATCH_MAX 64
|
||||
#define TIME_SUB_MS(tv1, tv2) ((tv1.tv_sec - tv2.tv_sec) * 1000 + (tv1.tv_usec - tv2.tv_usec) / 1000)
|
||||
|
||||
#define PRESP print_response
|
||||
@@ -81,7 +82,6 @@ int verify_response(const kvs_response_t *rsp, uint8_t expected_op,
|
||||
|
||||
|
||||
|
||||
#define KVS_BATCH_MAX 64
|
||||
|
||||
typedef struct {
|
||||
uint8_t buf[BATCH_SIZE];
|
||||
@@ -101,10 +101,8 @@ static void kvs_batch_init(kvs_batch_t *b)
|
||||
* 用 getcmd() 生成单条命令,然后 append 到 batch buffer
|
||||
* 返回:0 成功,-1 失败(太多条 or buffer 不够)
|
||||
*/
|
||||
static int kvs_batch_add(kvs_batch_t *b, uint8_t op, const char *key, const char *value)
|
||||
{
|
||||
static int kvs_batch_add(kvs_batch_t *b, uint8_t op, const char *key, const char *value){
|
||||
if (b->cnt >= KVS_BATCH_MAX) return -1;
|
||||
|
||||
uint8_t tmp[CMD_SIZE];
|
||||
int n = getcmd(op, key, value, tmp); // 你提供的函数
|
||||
if (n <= 0) return -1;
|
||||
@@ -124,6 +122,7 @@ static int kvs_batch_add(kvs_batch_t *b, uint8_t op, const char *key, const char
|
||||
*/
|
||||
static int kvs_batch_send(int fd, const kvs_batch_t *b)
|
||||
{
|
||||
printf("send : %d\n", b->len);
|
||||
return (int)send(fd, b->buf, b->len, 0);
|
||||
}
|
||||
|
||||
@@ -138,19 +137,26 @@ static int kvs_batch_recv_parse(int fd,
|
||||
uint8_t *recvbuf,
|
||||
int recvbuf_cap)
|
||||
{
|
||||
int nrecv = (int)recv(fd, recvbuf, recvbuf_cap, 0);
|
||||
if (nrecv <= 0) return -1;
|
||||
|
||||
int off = 0;
|
||||
int parsed = 0;
|
||||
int used = 0;
|
||||
|
||||
while (parsed < b->cnt && off < nrecv) {
|
||||
int consumed = parse_response(recvbuf + off, nrecv - off, &rsps[parsed]);
|
||||
if (consumed <= 0) break; // 不够解析/失败,简单处理:直接退出
|
||||
while(parsed < b->cnt){
|
||||
printf("recv loop: parsed=%d\n", parsed);
|
||||
int nrecv = (int)recv(fd, recvbuf+used, recvbuf_cap, 0);
|
||||
printf("recv nrecv=%d\n", nrecv);
|
||||
if (nrecv <= 0) return -1;
|
||||
|
||||
off += consumed;
|
||||
parsed++;
|
||||
int off = 0;
|
||||
|
||||
while (parsed < b->cnt) {
|
||||
int consumed = parse_response(recvbuf + used, nrecv - off, &rsps[parsed]);
|
||||
if (consumed <= 0) break; // 不够解析/失败,简单处理:直接退出
|
||||
|
||||
off += consumed;
|
||||
used+= consumed;
|
||||
parsed++;
|
||||
}
|
||||
printf("after parse: parsed=%d, used=%d\n", parsed, used);
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
Reference in New Issue
Block a user