一個小例子說明函數使用:函數
結構說明: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; }