c - sendfile 返回 -1 errno 29 非法查找

标签 c linux sockets

我是用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/

相关文章:

java - Linux- 找不到 javac 命令

java - JAVA 支持 INET 套接字系列吗?

c - 在 C11 中使用 _Noreturn

c - 当我们有 poll() 和 epoll() 时,为什么要使用 select()

linux - 如何重新分配 DJVU 文件中的页码?

java - java套接字可以在不压垮接收套接字的情况下进行多次连续写入吗?

c++ - 通过套接字 C++ 发送时位域值发生变化

c - 为什么要触发两次 SIGINT 才能按预期工作?

c - 如何在linux内核中实现新的调度方案

C++ 程序在 Linux 上正确打开文件,但在 Windows 上却不能