/* utils.cc
   Louis Solofrizzo 2019-10-17

   Utilities for pistache
*/

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

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;
}

/* 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 */

Fix broken compilation for trees without the PISTACHE_USE_SSL option
Common: Fix broken compilation for trees without the PISTACHE_USE_SSL option

Due to a brain-lag on my end, I've introduced a regression in commit
44e40478d604746963b898efd463a541ebbea824, because a SSL utility function
was compiling whether or not the SSL was enabled. It is now fixed,
apologies.

Pull Request: https://github.com/oktal/pistache/pull/623
Fixes: https://github.com/oktal/pistache/issues/621
Fixes: https://github.com/oktal/pistache/issues/622

Fork: https://git.mobley.ne02ptzero.me/~louis/pistache
Signed-off-by: Louis Solofrizzo <219d34e4f07f54ff278d7ec92ea24ddc58fdffc0@online.net>
