一个小例子说明函数使用:函数
结构说明:ui
struct iovec { void * iov_base //缓冲区地址 size_t iov_len //缓冲区输入/输出长度 }
#include "util.h" #include <sys/uio.h> int main(int argc , char **argv) { struct iovec v[2]; char buf1[] = "nihao"; char buf2[] = "fuck me"; v[0].iov_base = buf1; v[0].iov_len = 3; // 输入/输出 3个字节 v[1].iov_base = buf2; v[1].iov_len = 4; //输入/输出 4个字节 int n = writev(1,v,2); printf("\n write bytes:%d\n" , n); puts("reading from stdin"); n = readv(0,v,2); printf("read bytes:%d\n",n); printf("buf1:%s\n" ,buf1); printf("buf2:%s\n",buf2); return 0; }