1
我讀過手冊頁writev
,發現錯誤部分指出,c - 「writev」中允許的最大「iovcnt」參數?
EINVAL ...矢量計數
iovcnt
大於允許的最大大於小於零或。
但我怎麼能得到最大值?
PS:在我的OS(Ubuntu的14.04 x64)的這似乎是1024我通過下面的代碼檢查
#include <stdlib.h>
#include <fcntl.h>
#include <sys/uio.h>
char content[4000];
struct iovec vec[4000];
int main()
{
int n, i;
// int cnt = 1024; // OK
int cnt = 1025; // writev error
int fd = open("tmp.txt", O_WRONLY);
if (fd == -1) {
perror("open");
exit(1);
}
for (i = 0; i < cnt; ++i) {
content[i] = 'a' + i % 26;
vec[i].iov_base = content + i;
vec[i].iov_len = 1;
}
n = writev(fd, vec, cnt);
if (n == -1) {
perror("writev");
exit(1);
}
return 0;
}
非常感謝。看起來'IOV_MAX'沒有在我的系統上定義(編譯錯誤),但'sysconf(_SC_IOV_MAX)'工作。 – neuront 2014-12-03 12:58:15
使用'-D_XOPEN_SOURCE'編譯來獲取limits.h來定義'IOV_MAX'。 – mark4o 2014-12-03 12:59:04