Klaus Demo bjoern / df2d23b
Fix sendfile on BSD/OSX sendfile() on these platforms does not advance the input file descriptor cursor, so we'll have to count the offset explictly. Jonas Haag 2 years ago
3 changed file(s) with 17 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
1010 #include <sys/socket.h>
1111 #include <sys/types.h>
1212
13 Py_ssize_t portable_sendfile(int out_fd, int in_fd) {
13 Py_ssize_t portable_sendfile(int out_fd, int in_fd, off_t offset) {
1414 off_t len = SENDFILE_CHUNK_SIZE;
15 if(sendfile(in_fd, out_fd, 0, &len, NULL, 0) == -1)
15 if(sendfile(in_fd, out_fd, offset, &len, NULL, 0) == -1)
1616 return -1;
1717 return len;
1818 }
2222 #include <sys/socket.h>
2323 #include <sys/types.h>
2424
25 Py_ssize_t portable_sendfile(int out_fd, int in_fd) {
25 Py_ssize_t portable_sendfile(int out_fd, int in_fd, off_t offset) {
2626 off_t len;
27 if (sendfile(in_fd, out_fd, 0, SENDFILE_CHUNK_SIZE, NULL, &len, 0) == -1) {
27 if(sendfile(in_fd, out_fd, offset, SENDFILE_CHUNK_SIZE, NULL, &len, 0) == -1) {
2828 return -1;
2929 }
3030 return len;
3636
3737 #include <sys/sendfile.h>
3838
39 Py_ssize_t portable_sendfile(int out_fd, int in_fd) {
40 return sendfile(out_fd, in_fd, NULL, SENDFILE_CHUNK_SIZE);
39 Py_ssize_t portable_sendfile(int out_fd, int in_fd, off_t offset) {
40 return sendfile(out_fd, in_fd, &offset, SENDFILE_CHUNK_SIZE);
4141 }
4242
4343 #endif
00 #include <Python.h> /* for Py_ssize_t */
11
2 Py_ssize_t portable_sendfile(int out_fd, int in_fd);
2 Py_ssize_t portable_sendfile(int out_fd, int in_fd, off_t offset);
400400 {
401401 Py_ssize_t bytes_sent = portable_sendfile(
402402 request->client_fd,
403 ((FileWrapper*)request->iterable)->fd
403 ((FileWrapper*)request->iterable)->fd,
404 request->current_chunk_p
404405 );
405 if(bytes_sent == -1)
406 switch(bytes_sent) {
407 case -1:
406408 return handle_nonzero_errno(request);
407 return bytes_sent != 0;
409 case 0:
410 return false;
411 default:
412 request->current_chunk_p += bytes_sent;
413 return true;
414 }
408415 }
409416
410417 static bool