【发布时间】:2019-04-11 16:12:25
【问题描述】:
我在管道中写一些整数,当我结束时我写“11”。然后,当我从同一个管道读取数据时,我必须获取整数并对它们进行处理,当我得到“11”时,我应该终止。但我想不出任何解决方案可以同时在管道中读取 int 和 char (我知道这是基于 fifo 方法)。
有什么想法吗?
//THIS IS AN EXAMPLE CODE OF WHAT I WANT TO DO
//I am writing to the pipe
while(CONDITION)
write(mypipe, &random_int, sizeof(short));
write(mypipe, "1", sizeof("11"));
/* code... */
//I am reading from the pipe
while(TRUE){
read(mypipe, &received_int, sizeof(short));
// if strcmp(receiver_int, "11")==0 then exit;
// else do stuff with receiver_int
}
【问题讨论】: