forked from yuanrongxi/libpaxos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acceptor_main.c
50 lines (38 loc) · 885 Bytes
/
acceptor_main.c
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
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include "evpaxos.h"
void handle_sigint(int sig, short ev, void* arg)
{
struct event_base* base = arg;
printf("Caught signal %d\n", sig);
event_base_lookexit(base, NULL);
}
int main(int argc, const char* argv[])
{
int id;
struct event* sig;
struct evacceptor* acc;
struct event_base* base;
if(argc != 3){
printf("Usage %s id config\n", argv[0]);
return 0;
}
/*构建libevent base*/
base = event_base_new();
/*读取acceptor id,全局唯一*/
id = atoi(argv[1]);
/*创建一个acceptor 的事件响应器*/
acc = evacceptor_init(id, argv[2], base);
if(acc == NULL){
printf("Could not start the acceptor\n");
return 0;
}
sig = evsignal_new(base, SIGINT, handle_sigint, base);
evsignal_add(sig, NULL);
event_base_dispatch(base);
event_free(sig);
evacceptor_free(acc);
event_base_free(base);
return 1;
}