add network

This commit is contained in:
King
2024-05-18 14:10:08 +00:00
parent f4c0b74285
commit 5a7fa95d2c
6 changed files with 738 additions and 0 deletions

62
server.h Normal file
View File

@@ -0,0 +1,62 @@
#ifndef __SERVER_H__
#define __SERVER_H__
#define BUFFER_LENGTH 1024
#define ENABLE_HTTP 0
#define ENABLE_WEBSOCKET 0
#define ENABLE_KVSTORE 1
typedef int (*RCALLBACK)(int fd);
struct conn {
int fd;
char rbuffer[BUFFER_LENGTH];
int rlength;
char wbuffer[BUFFER_LENGTH];
int wlength;
RCALLBACK send_callback;
union {
RCALLBACK recv_callback;
RCALLBACK accept_callback;
} r_action;
int status;
#if 1 // websocket
char *payload;
char mask[4];
#endif
};
#if ENABLE_HTTP
int http_request(struct conn *c);
int http_response(struct conn *c);
#endif
#if ENABLE_WEBSOCKET
int ws_request(struct conn *c);
int ws_response(struct conn *c);
#endif
#if ENABLE_KVSTORE
int kvs_request(struct conn *c);
int kvs_response(struct conn *c);
#endif
#endif