author | Alberto Bertogli
<albertito@gmail.com> 2007-06-01 18:48:29 UTC |
committer | Alberto Bertogli
<albertito@gmail.com> 2007-06-01 18:48:29 UTC |
parent | 54d9e83e20b123811b1abef1f8cea9fd4a419def |
nmdb/Makefile | +18 | -1 |
nmdb/net.c | +26 | -18 |
nmdb/tcp-stub.c | +18 | -0 |
nmdb/tipc-stub.c | +18 | -0 |
diff --git a/nmdb/Makefile b/nmdb/Makefile index a37dac3..c58d289 100644 --- a/nmdb/Makefile +++ b/nmdb/Makefile @@ -1,6 +1,10 @@ +ENABLE_TIPC = 1 +ENABLE_TCP = 1 + CFLAGS += -std=c99 -Wall -O3 ALL_CFLAGS = -D_XOPEN_SOURCE=500 $(CFLAGS) +ALL_CFLAGS += -DENABLE_TIPC=$(ENABLE_TIPC) -DENABLE_TCP=$(ENABLE_TCP) ifdef DEBUG ALL_CFLAGS += -g @@ -18,7 +22,20 @@ endif PREFIX=/usr/local -OBJS = be-qdbm.o cache.o db.o queue.o net.o parse.o tcp.o tipc.o main.o +OBJS = be-qdbm.o cache.o db.o queue.o net.o parse.o main.o + +ifeq ($(ENABLE_TIPC), 1) + OBJS += tipc.o +else + OBJS += tipc-stub.o +endif + +ifeq ($(ENABLE_TCP), 1) + OBJS += tcp.o +else + OBJS += tcp-stub.o +endif + default: all diff --git a/nmdb/net.c b/nmdb/net.c index 3cb8d9a..0e61c5e 100644 --- a/nmdb/net.c +++ b/nmdb/net.c @@ -29,30 +29,38 @@ static void passive_to_active_sighandler(int fd, short event, void *arg) void net_loop(void) { - int tipc_fd, tcp_fd; + int tipc_fd = -1; + int tcp_fd = -1; struct event tipc_evt, tcp_evt, sigterm_evt, sigint_evt, sigusr2_evt; - tipc_fd = tipc_init(); - if (tipc_fd < 0) { - perror("Error initializing TIPC"); - exit(1); - } + event_init(); - tcp_fd = tcp_init(); - if (tcp_fd < 0) { - perror("Error initializing TCP"); - exit(1); - } + /* ENABLE_TIPC and ENABLE_TCP are preprocessor constants defined on + * the command line by make. */ - event_init(); + if (ENABLE_TIPC) { + tipc_fd = tipc_init(); + if (tipc_fd < 0) { + perror("Error initializing TIPC"); + exit(1); + } - event_set(&tipc_evt, tipc_fd, EV_READ | EV_PERSIST, tipc_recv, - &tipc_evt); - event_add(&tipc_evt, NULL); + event_set(&tipc_evt, tipc_fd, EV_READ | EV_PERSIST, tipc_recv, + &tipc_evt); + event_add(&tipc_evt, NULL); + } + + if (ENABLE_TCP) { + tcp_fd = tcp_init(); + if (tcp_fd < 0) { + perror("Error initializing TCP"); + exit(1); + } - event_set(&tcp_evt, tcp_fd, EV_READ | EV_PERSIST, tcp_newconnection, - &tcp_evt); - event_add(&tcp_evt, NULL); + event_set(&tcp_evt, tcp_fd, EV_READ | EV_PERSIST, tcp_newconnection, + &tcp_evt); + event_add(&tcp_evt, NULL); + } signal_set(&sigterm_evt, SIGTERM, exit_sighandler, &sigterm_evt); signal_add(&sigterm_evt, NULL); diff --git a/nmdb/tcp-stub.c b/nmdb/tcp-stub.c new file mode 100644 index 0000000..d3fffdc --- /dev/null +++ b/nmdb/tcp-stub.c @@ -0,0 +1,18 @@ + +/* TCP stub file, used when TCP is not compiled in. */ + +int tcp_init(void) +{ + return -1; +} + +void tcp_close(int fd) +{ + return; +} + +void tcp_recv(int fd, short event, void *arg) +{ + return; +} + diff --git a/nmdb/tipc-stub.c b/nmdb/tipc-stub.c new file mode 100644 index 0000000..a717389 --- /dev/null +++ b/nmdb/tipc-stub.c @@ -0,0 +1,18 @@ + +/* TIPC stub file, used when TIPC is not compiled in. */ + +int tipc_init(void) +{ + return -1; +} + +void tipc_close(int fd) +{ + return; +} + +void tipc_recv(int fd, short event, void *arg) +{ + return; +} +