Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <time.h>
- #include <pthread.h>
- #define FIFO_SERVER "FIFO_SERVER"
- #define FIFO_CLIENT "MYFIFO"
- static bool flag = true;
- void* threadFunc(void* thread_data){
- sleep(30);
- flag = false;
- }
- int main()
- {
- unlink(FIFO_CLIENT);
- FILE* fp;
- char readbuf[80];
- if((fp = fopen(FIFO_SERVER, "w")) == NULL)
- {
- perror("open error");
- exit(1);
- }
- umask(0); // set file mask for creating files
- mknod(FIFO_CLIENT, S_IFIFO | 0777, 0); // create FIFO file
- // send data to server
- fputs(FIFO_CLIENT, fp);
- fclose(fp);
- // read echo replay from server
- int count = 0;
- if((fp = fopen(FIFO_CLIENT, "r")) == NULL)
- {
- perror("open error");
- exit(1);
- }
- pthread_t t1;
- pthread_create(&t1, NULL, threadFunc, NULL);
- while(flag){
- fgets(readbuf,1,fp);
- count++;
- }
- printf("Count symbols: %d\n", count);
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement