From 191aa73fee9c955251165aa3c2f6ee5aad7ddbce Mon Sep 17 00:00:00 2001 From: Amit Bakshi Date: Sat, 25 Nov 2017 10:24:10 -0800 Subject: [PATCH] Add simple test from README.md --- Makefile | 28 +++++++++++++++++++++------- test.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 test.c diff --git a/Makefile b/Makefile index b530e1e..6491ad7 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,31 @@ PREFIX = /usr/local -CFLAGS += -Wall -Werror -std=c99 -c -D_GNU_SOURCE +CFLAGS += -Wall -Werror -std=c99 -D_GNU_SOURCE .PHONY: - all clean install uninstall + all clean install uninstall test -all: - $(CC) $(CFLAGS) src/flingfd.c -o src/.flingfd.o - $(AR) -rc libflingfd.a src/.flingfd.o +all: libflingfd.a test-sender test-receiver + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +libflingfd.a: src/flingfd.o + $(AR) -rc $@ $^ + +test-sender: test.c src/flingfd.c + $(CC) $(CFLAGS) -DSENDER $^ -o $@ + +test-receiver: test.c src/flingfd.c + $(CC) $(CFLAGS) $^ -o $@ + +test: test-sender test-receiver + ./test-sender & +#include +#include +#include + +char buf[32]; + +void send_my_stdout() { + int fd = fileno(stdout); + flingfd_simple_send("/tmp/some_unique_path", fd); +} + +void write_to_their_stdout() { + int fd = flingfd_simple_recv("/tmp/some_unique_path"); + int n = snprintf(buf,32,"Hello world from %d\n", getpid()); + write(fd, buf, n+1); +} + +int main() { +#ifdef SENDER + printf("Hello, I'm the sender My pid: %d\n", getpid()); + write_to_their_stdout(); +#else + printf("Hello, I'm receiver. My pid: %d\n", getpid()); + send_my_stdout(); +#endif + return 0; +}