Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <errno.h>
- #include "proto.h"
- int main(int argc, char** argv)
- {
- int fdfifo, fdoutfifo;
- char buf[RESULT_FIFO_PATH_BUF_SIZE];
- query_t query;
- result_t result;
- if(mkfifo(QUERY_FIFO_PATH, S_IRUSR | S_IWUSR) < 0 && errno != EEXIST)
- {
- perror("mkfifo");
- abort();
- }
- while(1)
- {
- if((fdfifo = open(QUERY_FIFO_PATH, O_RDONLY)) < 0)
- {
- perror("open");
- abort();
- }
- while(read(fdfifo, &query, sizeof(query)))
- {
- result.rs = query.m1 * query.m2;
- sprintf(buf, RESULT_FIFO_PATH_FMT, query.pid);
- if((fdoutfifo = open(buf, O_WRONLY)) < 0)
- {
- perror("open");
- abort();
- }
- write(fdoutfifo, &result, sizeof(result));
- close(fdoutfifo);
- printf("%ld -> [%s]\n", result.rs, buf);
- }
- close(fdfifo);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment