~ne02ptzero/pistache

ref: 27eda3a7860e6c0835543c6fcb358d3ff90a79ad pistache/src/common/utils.cc -rw-r--r-- 775 bytes
27eda3a7 — Louis Solofrizzo Common: Fix broken compilation for trees without the PISTACHE_USE_SSL option 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* utils.cc
   Louis Solofrizzo 2019-10-17

   Utilities for pistache
*/

#include <pistache/peer.h>
#include <unistd.h>

#ifdef PISTACHE_USE_SSL

ssize_t SSL_sendfile(SSL *out, int in, off_t *offset, size_t count)
{
    unsigned char       buffer[4096] = { 0 };
    ssize_t             ret;
    ssize_t             written;
    size_t              to_read;

    if (in == -1)
        return -1;

    to_read = sizeof(buffer) > count ? count : sizeof(buffer);

    if (offset != NULL)
        ret = pread(in, buffer, to_read, *offset);
    else
        ret = read(in, buffer, to_read);

    if (ret == -1)
        return -1;

    written = SSL_write(out, buffer, ret);
    if (offset != NULL)
        *offset += written;

    return written;
}

#endif /* PISTACHE_USE_SSL */