LINUX.ORG.RU

Системный вызов sendfile ???


0

0

Здравствуйте !

Проблема с системным вызовом sendfile при работе с ядрами 2.4.33 2.6.21

На 2.4.33 работает нормально на 2.6.x ошибки ...

Выполняю следующий код :

#include <fcntl.h>

#include <stdlib.h>

#include <stdio.h>

#include <sys/sendfile.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <unistd.h>

int main (int argc, char* argv[]) {

int read_fd;

int write_fd;

struct stat stat_buf;

off_t offset = 0;

read_fd = open (argv[1], O_RDONLY);

fstat (read_fd, &stat_buf);

write_fd = open (argv[2], O_WRONLY | O_CREAT, stat_buf.st_mode);

sendfile (write_fd, read_fd, &offset, stat_buf.st_size);

close (read_fd);

close (write_fd);

return 0;

}

В итоге 2.4.33 копирует два файла нормально а 2.6.х вываливается с ошибками ...

anonymous

Ты б хоть код ошибки привел.

tailgunner ★★★★★
()

> Other Unixes often implement sendfile with different semantics and prototypes. It should not be used in portable programs.

Читай и бейся головой об стену, пока не наступит просветление.

paul7
()
Ответ на: комментарий от generatorglukoff

А если совсем точным быть, то вот

Presently (Linux 2.6.9): in_fd, must correspond to a file which supports mmap()-like operations (i.e., it cannot be a socket); and out_fd must refer to a socket.

n Linux 2.4 and earlier, out_fd could refer to a regular file, and sendfile() changed the current offset of that file.

Из man sendfile() http://linux.die.net/man/2/sendfile

Uncle_Theodore ★★
()
Ответ на: комментарий от Uncle_Theodore

Спасибо ! как понял параметр out должен быть сокетом ... хотя в 2.4.х он мог быть обычным файлом

anonymous
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.