我是用sendfile在client和server之间收发文件,发送文件没问题,但是接收文件时返回-1,errno是29 illegal seek,不知道是什么问题.
int fd = open(filename, O_WRONLY | O_CREAT);
off_t offset = 0;
int ret = sendfile(fd, sockfd, &offset, filelen);
printf("ret = %d errno=%d\n", ret, errno);
>>> ret = -1 errno = 29
最佳答案
sendfile()
的手册页说:
The
in_fd
argument must correspond to a file which supports mmap(2)-like operations (i.e., it cannot be a socket).
in_fd
是第二个参数,您将其命名为 sockfd
。这表明您的问题是输入文件描述符不适用于 sendfile()
。
关于c - sendfile 返回 -1 errno 29 非法查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20256917/