我想尝试 splice 系统调用。我有这个功能 - 它应该将一个文件的内容复制到另一个文件:
static void test_splice( int in, int out ) {
int i = 0, rcvd = 0;
int filedes[2];
off_t off = 0;
if ( pipe( filedes ) < 0 ) {
perror( "Kicha pipe" );
exit( EXIT_FAILURE );
}
for ( i = 0; i < NUMLOOPS; ++i ) {
if ( ( rcvd = splice( in, NULL, filedes[1], NULL, BUFSIZE, SPLICE_F_MORE | SPLICE_F_MOVE ) ) < 0 ) {
perror( "splice" );
exit( EXIT_FAILURE );
}
if ( splice( filedes[0], NULL, out, NULL, rcvd, SPLICE_F_MORE | SPLICE_F_MOVE ) < 0 ) {
perror( "splice" );
exit( EXIT_FAILURE );
}
}
}
在第一次迭代中对 splice 的第二次调用每次都会返回 EINVAL(来自 perror 的无效参数)——可能是什么原因?
最佳答案
来自 splice(2)
:
ERRORS
...
EINVAL Target filesystem doesn't support splicing; target file is
opened in append mode; neither of the file descriptors refers to
a pipe; or offset given for nonseekable device.
...
OP 的评论表明他以追加模式打开文件。
关于c - 调用 linux splice() 时参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2580390/