fifo_write
/*****************************************************
copyright (C), 2014-2015, Lighting Studio. Co., Ltd.
File name:
Author:Jerey_Jobs Version:0.1 Date:
Description:
Funcion List:
*****************************************************/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <memory.h>
#include <stdlib.h>
#define FIFOSERVER "/tmp/fifoserver"
int main()
{
int fd;
char w_buf[100];
int real_wnum;
memset(w_buf,0,100);
if(mkfifo(FIFOSERVER,O_CREAT) < 0)
{
perror("mkfifo error!");
exit(-1);
}
fd = open(FIFOSERVER,O_WRONLY | O_NONBLOCK);
//fd = open(FIFOSERVER, O_WRONLY);
if(-1 == fd)
{
perror("open error!");
exit(-1);
}
printf("please input message:\n");
scanf("%s",w_buf);
real_wnum = write(fd,w_buf,100);
if(-1 == real_wnum)
{
perror("write error!");
exit(-1);
}
close(fd);
return 0;
}
fifo_write
/*****************************************************
copyright (C), 2014-2015, Lighting Studio. Co., Ltd.
File name:
Author:Jerey_Jobs Version:0.1 Date:
Description:
Funcion List:
*****************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <memory.h>
#define FIFOSERVER "/tmp/fifoserver"
int main(int argc,char ** argv)
{
char r_buf[100];
int fd;
int r_size;
int ret_size;
r_size = atoi(argv[1]);
printf("require real read bytes is %d\n",r_size);
memset(r_buf,0,100);
fd = open(FIFOSERVER,O_RDONLY);
//fd = open(FIFOSERVER,O_RDONLY | O_NONBLOCK);
if(-1 == fd)
{
perror("open error!");
exit(-1);
}
ret_size = read(fd,r_buf,r_size);
if(-1 == ret_size)
{
perror("read error!");
exit(-1);
}
printf("real read %d bytes ,is %s\n",ret_size,r_buf);
unlink(FIFOSERVER);
return 0;
}