Make request parsing reentrant
This commit is contained in:
@@ -17,7 +17,6 @@ typedef struct RdbClient {
|
||||
} RdbClient;
|
||||
|
||||
void rdb_client_init(RdbClient *self, int connfd);
|
||||
ssize_t rdb_client_read(RdbClient *self, char *buf, size_t len);
|
||||
void rdb_client_begin_packet(RdbClient *self);
|
||||
bool rdb_client_write_str(RdbClient *self, const char *str);
|
||||
bool rdb_client_write_str_hex(RdbClient *self, const char *str);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef V810_HEX_H_
|
||||
#define V810_HEX_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool parse_hex_digit(char digit, char *out);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef RDBSERVER_REQUEST_H
|
||||
#define RDBSERVER_REQUEST_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define INBUF_LEN 256
|
||||
|
||||
typedef enum rdb_read_result_t {
|
||||
read_result_success,
|
||||
read_result_error,
|
||||
read_result_pending,
|
||||
read_result_disconnected,
|
||||
} rdb_read_result_t;
|
||||
|
||||
typedef enum rdb_read_state_t {
|
||||
read_state_header,
|
||||
read_state_body,
|
||||
read_state_body_escape,
|
||||
read_state_checksum_1,
|
||||
read_state_checksum_2,
|
||||
} rdb_read_state_t;
|
||||
|
||||
typedef struct RdbRequest {
|
||||
int connfd;
|
||||
struct Buffer {
|
||||
char buf[INBUF_LEN];
|
||||
size_t len;
|
||||
size_t index;
|
||||
} inbuf;
|
||||
rdb_read_state_t state;
|
||||
char *cmd;
|
||||
size_t cmdlen;
|
||||
size_t outlen;
|
||||
char chk;
|
||||
} RdbRequest;
|
||||
|
||||
void rdb_request_init(RdbRequest *req, int connfd, char *cmd, size_t cmdlen);
|
||||
void rdb_request_reset(RdbRequest *req);
|
||||
rdb_read_result_t rdb_request_read(RdbRequest *req, size_t *len);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user