没有用好man的下场呵呵,找个错误一直不知所措。
先看splice函数:
1 SPLICE(2) Linux Programmer's Manual SPLICE(2)
2
3 NAME4 splice - splice data to/froma pipe5
6 SYNOPSIS7 #define _GNU_SOURCE /* See feature_test_macros(7) */
8 #include
9
10 ssize_t splice(int fd_in, loff_t *off_in, intfd_out,11 loff_t *off_out, size_t len, unsigned int flags);
主要作用就是移动两个文件描述符中的数据,实现零拷贝操作。具体详见man或者google。
说一下遇到的坑:看着书上知道它包含于fcntl头文件,可在编译的时候遇到了未知的未声明错误,找了半天百度终于找到答案。
splice.c:48:53: error: ‘SPLICE_F_MORE’ undeclared (first use in this function)
ret=splice(connfd,NULL,pipefd[1],NULL,32768,SPLICE_F_MORE|SPLICE_F_MOVE);
^
splice.c:48:53: note: each undeclared identifier is reported only once for each function it appears in
splice.c:48:67: error: ‘SPLICE_F_MOVE’ undeclared (first use in this function)
ret=splice(connfd,NULL,pipefd[1],NULL,32768,SPLICE_F_MORE|SPLICE_F_MOVE);
其实man里就可以看到还需要定义一个功能测试宏, _GNU_SOURCE,注意这里的顺序,小坑,不然依然编译不过。
那么这个测试宏是干什么的呢,继续man下去:
EATURE_TEST_MACROS(7) Linux Programmer's Manual FEATURE_TEST_MACROS(7)
NAME
feature_test_macros-feature test macros
SYNOPSIS
#includeDESCRIPTION
Feature test macros allow the programmer to control the definitions
that are exposed by system header files when a programis compiled.
当程序被编译的时候,允许开发者控制被系统头文件所包含的宏。
暂时也不明白,先就酱。