blob: 7e9a839fd6d0dd138de145205d17c964f66ebd82 (
plain)
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
48
49
50
51
52
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "socket.h"
#include "display.h"
#include "audio.h"
#include "typedef.h"
static int fd;
void on_recv(char *buf, int numbytes)
{
// read and play audio
pid_t p = fork();
if(p < 0) {
fputs("fork: failed", stderr);
exit(1);
} else if(p > 0) {
write(fd, &(buf[REC_CAP]), numbytes-REC_CAP);
} else {
audio_play(buf);
exit(0);
}
// audio_play(buf);
// write(fd, &(buf[REC_CAP]), numbytes-REC_CAP);
}
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]);
}
}
|