进程间与网络通信详解
进程间双向管道通信测试
为了测试pipe_2way函数,我们编写一个程序,将字符发送给lowercase命令,然后接收转换后的字符串。这里使用readl函数来完成接收操作,其代码如下:
int readl(int fd, char s[], int size) { char *tmp = s; while (0 < --size && read(fd, tmp, 1)!=0 && *tmp++ !='\n'); *tmp = '\0'; /* string terminator */ return(tmp - s); }下面是测试pipe_2way的主程序pipe2way.c:
/******** pipe2way.c ********/ /* headers, readl, and pipe_2way functions */ #define SIZE 256 int main() { int pd[2]; char *str[2]; char test_string[] = "IPC WITH TWO-WAY PIPE.\n"; char buf[SIZE]; char *tmp = buf; str[0] = "./lo