-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_server.c
More file actions
34 lines (26 loc) · 973 Bytes
/
Copy pathhello_server.c
File metadata and controls
34 lines (26 loc) · 973 Bytes
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
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include "ep_engine/epoll_event_engine.h"
#include "msg_pass/mp_server.h"
#define SERVER_PORT 30030
#define NUM_WORKER_THREAD 4
void handle_request(Mp_srv_request* request, void* cb_arg) {
const char* req_msg = request->msg;
// do work with req_msg
int n;
char client_name[256];
memset(client_name, 0, sizeof(client_name));
sscanf(req_msg, "Hello world(%[^)]) %d\n", client_name, &n);
printf("hello_server.c: got msg from client(%s): %s\n",
client_name, req_msg);
char reply_msg[MP_MAXMSGLEN];
sprintf(reply_msg, "This is hello reply(%s) %d\n", client_name, n);
mp_server_request_done(request, reply_msg);
}
int main(int argc, char** argv) {
EP_engine* engine = ep_engine_create(true, NUM_WORKER_THREAD);
Mp_server* server = mp_server_create(SERVER_PORT, engine, handle_request, NULL);
ep_engine_start_event_loop(engine);
return 0;
}