Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 & </dev/null; MYPID=$$! && \
./test-receiver | grep -q "$$MYPID"

clean:
rm -f libflingfd.a src/.flingfd.o
rm -f libflingfd.a src/flingfd.o test-receiver test-sender

install: all
install: libflingfd.a
cp src/flingfd.h $(PREFIX)/include
cp libflingfd.a $(PREFIX)/lib

Expand Down
28 changes: 28 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <flingfd.h>

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;
}