-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.h
36 lines (31 loc) · 992 Bytes
/
server.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
#ifndef __RPCH_SERVER_H_
#define __RPCH_SERVER_H_
#include <stdint.h>
#include "argument.h"
#include "error.h"
#include "hashmap.h"
#include "request.h"
#include "threadpool.h"
typedef struct server {
int lfd;
int epoll_fd;
uint16_t port;
uint32_t ip;
threadpool_t* pool;
hashmap_t* services;
} server_t;
struct server_attr {
int thread_cnt;
};
struct server* server_create();
void server_listen(struct server* svr, const char* addr, struct server_attr*,
error_t* err);
void server_destroy(struct server*);
static inline void server_register(server_t* svr, char* service_method,
void (*handler)(request_t* req, error_t* err,
struct argument* resp)) {
hashmap_set(svr->services, service_method, (void*)handler);
}
void build_resp(struct argument* resp, uint16_t type_kind,
const char* type_name, uint32_t data_len, char* data);
#endif