TetaTricks/code/fifo-rx.c

30 lines
570 B
C
Raw Normal View History

2021-08-25 16:18:34 +11:00
/*** named pipe --- receiver ***/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h> /* for mkfifo */
#include <fcntl.h>
#include "my-fifo.h"
int main(int argc, char *argv[])
{
int fifo;
Message message;
double localTS;
2021-08-29 02:06:26 +11:00
if (argc!=2) {
fprintf(stderr, "%s need a fifo name\n", argv[0]);
exit(1);
}
fifo = mkfifo(argv[1], O_RDONLY|O_CREAT);
if (-1==fifo) {
2021-08-25 16:18:34 +11:00
perror("mkfifo fail");
exit(2);
}
read(fifo, &message, sizeof(Message));
localTS = dtime();
printf("%f %f\n", localTS, message.timestamp);
close(fifo);
return 0;
}