aboutsummaryrefslogtreecommitdiff
path: root/src/listener.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/listener.c')
-rw-r--r--src/listener.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/listener.c b/src/listener.c
new file mode 100644
index 0000000..0a5df2d
--- /dev/null
+++ b/src/listener.c
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "socket.h"
+#include "display.h"
+#include "typedef.h"
+
+static int fd;
+
+void on_recv(char *buf, int numbytes)
+{
+ // read and play audio
+ write(fd, buf, numbytes);
+}
+
+int main(int argc, char **argv)
+{
+ int pipefd[2];
+ if(pipe2(pipefd, O_NONBLOCK) == -1) {
+ fputs("pipe: failed", stderr);
+ return 1;
+ }
+
+ pid_t p = fork();
+ if(p < 0) {
+ fputs("fork: failed", stderr);
+ return 1;
+ } else if(p > 0) {
+ close(pipefd[0]);
+ fd = pipefd[1];
+ return listener("4950", &on_recv);
+ } else {
+ close(pipefd[1]);
+ display(&argc, argv, pipefd[0]);
+ }
+}