~ubuntu-branches/ubuntu/oneiric/samba/oneiric-security

« back to all changes in this revision

Viewing changes to source/lib/sendfile.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-07-21 17:53:23 UTC
  • mfrom: (0.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050721175323-m3oh6aoigywohfnq
Tags: 3.0.14a-6ubuntu1
Resynchronise with Debian, resolving merge conflicts (#12360)

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
                        nwritten = sendfile(tofd, fromfd, &offset, total);
66
66
#endif
67
67
                } while (nwritten == -1 && errno == EINTR);
68
 
                if (nwritten == -1)
 
68
                if (nwritten == -1) {
 
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.
 
77
                                 */
 
78
                                errno = EINTR; /* Normally we can never return this. */
 
79
                        }
69
80
                        return -1;
 
81
                }
70
82
                if (nwritten == 0)
71
83
                        return -1; /* I think we're at EOF here... */
72
84
                total -= nwritten;
131
143
                do {
132
144
                        nwritten = sendfile(tofd, fromfd, &small_offset, small_total);
133
145
                } while (nwritten == -1 && errno == EINTR);
134
 
                if (nwritten == -1)
 
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.
 
155
                                 */
 
156
                                errno = EINTR; /* Normally we can never return this. */
 
157
                        }
135
158
                        return -1;
 
159
                }
136
160
                if (nwritten == 0)
137
161
                        return -1; /* I think we're at EOF here... */
138
162
                small_total -= nwritten;
250
274
                hdtrl[0].iov_len = hdr_len = 0;
251
275
        }
252
276
        hdtrl[1].iov_base = NULL;
253
 
        hdtrl[1].iov_base = 0;
 
277
        hdtrl[1].iov_len = 0;
254
278
 
255
279
        total = count;
256
280
        while (total + hdtrl[0].iov_len) {
371
395
        return count + hdr_len;
372
396
}
373
397
 
 
398
#elif defined(AIX_SENDFILE_API)
 
399
 
 
400
/* BEGIN AIX SEND_FILE */
 
401
 
 
402
/* Contributed by William Jojo <jojowil@hvcc.edu> */
 
403
#include <sys/socket.h>
 
404
 
 
405
ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)
 
406
{
 
407
        size_t total=0;
 
408
        struct sf_parms hdtrl;
 
409
 
 
410
        /* Set up the header/trailer struct params. */
 
411
        if (header) {
 
412
                hdtrl.header_data = header->data;
 
413
                hdtrl.header_length = header->length;
 
414
        } else {
 
415
                hdtrl.header_data = NULL;
 
416
                hdtrl.header_length = 0;
 
417
        }
 
418
        hdtrl.trailer_data = NULL;
 
419
        hdtrl.trailer_length = 0;
 
420
 
 
421
        hdtrl.file_descriptor = fromfd;
 
422
        hdtrl.file_offset = offset;
 
423
        hdtrl.file_bytes = count;
 
424
 
 
425
        while ( hdtrl.file_bytes + hdtrl.header_length ) {
 
426
                ssize_t ret;
 
427
 
 
428
                /*
 
429
                 Return Value
 
430
 
 
431
                 There are three possible return values from send_file:
 
432
 
 
433
                 Value Description
 
434
 
 
435
                 -1 an error has occurred, errno contains the error code.
 
436
 
 
437
                 0 the command has completed successfully.
 
438
 
 
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.
 
442
                */
 
443
                do {
 
444
                        ret = send_file(&tofd, &hdtrl, 0);
 
445
                } while ( (ret == 1) || (ret == -1 && errno == EINTR) );
 
446
                if ( ret == -1 )
 
447
                        return -1;
 
448
        }
 
449
 
 
450
        return count + header->length;
 
451
}
 
452
/* END AIX SEND_FILE */
 
453
 
374
454
#else /* No sendfile implementation. Return error. */
375
455
 
376
456
ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)