65
65
nwritten = sendfile(tofd, fromfd, &offset, total);
67
67
} while (nwritten == -1 && errno == EINTR);
69
if (errno == ENOSYS) {
70
/* Ok - we're in a world of pain here. We just sent
71
* the header, but the sendfile failed. We have to
72
* emulate the sendfile at an upper layer before we
73
* disable it's use. So we do something really ugly.
74
* We set the errno to a strange value so we can detect
75
* this at the upper level and take care of it without
76
* layer violation. JRA.
78
errno = EINTR; /* Normally we can never return this. */
71
83
return -1; /* I think we're at EOF here... */
132
144
nwritten = sendfile(tofd, fromfd, &small_offset, small_total);
133
145
} while (nwritten == -1 && errno == EINTR);
146
if (nwritten == -1) {
147
if (errno == ENOSYS) {
148
/* Ok - we're in a world of pain here. We just sent
149
* the header, but the sendfile failed. We have to
150
* emulate the sendfile at an upper layer before we
151
* disable it's use. So we do something really ugly.
152
* We set the errno to a strange value so we can detect
153
* this at the upper level and take care of it without
154
* layer violation. JRA.
156
errno = EINTR; /* Normally we can never return this. */
136
160
if (nwritten == 0)
137
161
return -1; /* I think we're at EOF here... */
138
162
small_total -= nwritten;
371
395
return count + hdr_len;
398
#elif defined(AIX_SENDFILE_API)
400
/* BEGIN AIX SEND_FILE */
402
/* Contributed by William Jojo <jojowil@hvcc.edu> */
403
#include <sys/socket.h>
405
ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)
408
struct sf_parms hdtrl;
410
/* Set up the header/trailer struct params. */
412
hdtrl.header_data = header->data;
413
hdtrl.header_length = header->length;
415
hdtrl.header_data = NULL;
416
hdtrl.header_length = 0;
418
hdtrl.trailer_data = NULL;
419
hdtrl.trailer_length = 0;
421
hdtrl.file_descriptor = fromfd;
422
hdtrl.file_offset = offset;
423
hdtrl.file_bytes = count;
425
while ( hdtrl.file_bytes + hdtrl.header_length ) {
431
There are three possible return values from send_file:
435
-1 an error has occurred, errno contains the error code.
437
0 the command has completed successfully.
439
1 the command was completed partially, some data has been
440
transmitted but the command has to return for some reason,
441
for example, the command was interrupted by signals.
444
ret = send_file(&tofd, &hdtrl, 0);
445
} while ( (ret == 1) || (ret == -1 && errno == EINTR) );
450
return count + header->length;
452
/* END AIX SEND_FILE */
374
454
#else /* No sendfile implementation. Return error. */
376
456
ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)