FIFOs implementation

前端 未结 5 1165
悲哀的现实
悲哀的现实 2020-12-17 04:35

Consider the following code:

writer.c

mkfifo(\"/tmp/myfifo\", 0660);

int fd = open(\"/tmp/myfifo\", O_WRONLY);

char *foo, *bar;

...

write(fd, foo         


        
5条回答
  •  一向
    一向 (楼主)
    2020-12-17 04:42

    A separator is one way to go about it, and this will work fine, as long as you know the order of your data, and you use the separator as only a separator, and never as part of your data.

    Another way is to precede each write to the pipe with the number of bytes to follow, in a fixed width. Thus, you will know how much data is about to come down the pipe. Use a fixed width, so you know exactly how long the width field will be, so you know both when to start and stop reading each chunk of data.

提交回复
热议问题