-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.h
65 lines (56 loc) · 1.63 KB
/
main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef __TIDIS_H
#define __TIDIS_H
#define TIDIS_OBJECT_STRING 1
#include "config.h"
// event loop
#include "event/ev_factory.h"
// data structure
#include "datastructure/string.h"
#include "datastructure/hashtable.h"
// command protocol parser
#include "protocol/protocol.h"
// server config struct
// I prefer char array other than char * in struct
// main.c
typedef struct server_config_struct {
char host[ 32 ];
char port[ 8 ];
char event[ 8 ];
char daemonize[ 4 ];
} server_config_struct;
typedef struct config_item {
char key[ 16 ];
char value[ 32 ];
} config_item_struct;
// database struct
typedef struct db_struct {
// 键key的空间,一个hashtable数据结构
ht_st * key;
// 过期时间key的空间,另一个hashtable数据结构
ht_st * expire; // 暂时无用
} db_struct;
// client struct
typedef struct client_struct {
int fd;
struct sds_struct * io_buffer; // input buffer, data from client to server
} client_struct;
// server struct in main.c
typedef struct server_struct {
server_config_struct * config;
int listen_socket_fd;
db_struct * db; // 指向数据库的指针
// client link list
int db_num; // 数据库数量.暂时无用,保留
} server_struct;
// main.c : function prototype
server_config_struct * parse_config_file();
server_struct * init_server( server_config_struct *, ev_loop_struct * );
void net_accept_tcp_connect_processor( ev_loop_struct *, int );
void read_from_client( ev_loop_struct *, int );
bool daemonize();
void net_set_nonblock( int );
// function.c
void ltrim( char * );
void rtrim( char * );
void trim( char * );
#endif