Exemple #1
0
int mk_http_send_file(struct client_session *cs, struct session_request *sr)
{
    long int nbytes = 0;

    nbytes = mk_socket_send_file(cs->socket, sr->fd_file,
                                 &sr->bytes_offset, sr->bytes_to_send);

    if (nbytes > 0) {
        sr->bytes_to_send -= nbytes;
        if (sr->bytes_to_send == 0) {
            mk_server_cork_flag(cs->socket, TCP_CORK_OFF);
        }
    }

    sr->loop++;

    /*
     * In some circumstances when writing data, the connection can get broken.
     * So, we must be aware of that.
     *
     * Also, if for some reason the file that is being served changes it's size
     * we can get a zero bytes send as return value. We need to validate the
     * return values <= zero
     */
    if (mk_unlikely(nbytes <= 0)) {
        MK_TRACE("sendfile() = -1;");
        return EXIT_ABORT;
    }

    return sr->bytes_to_send;
}
Exemple #2
0
static inline size_t channel_write_stream_file(struct mk_channel *channel,
                                               struct mk_stream *stream)
{
    long int bytes = 0;

    MK_TRACE("[CH %i] STREAM_FILE %i, bytes=%lu",
             channel->fd, stream->fd, stream->bytes_total);

    /* Direct write */
    bytes = mk_socket_send_file(channel->fd,
                                stream->fd,
                                &stream->bytes_offset,
                                stream->bytes_total
                                );
    MK_TRACE("[CH=%d] [FD=%i] WRITE STREAM FILE: %lu bytes",
             channel->fd, stream->fd, bytes);

    return bytes;
}
Exemple #3
0
int mk_http_send_file(struct client_session *cs, struct session_request *sr)
{
    long int nbytes = 0;

    nbytes = mk_socket_send_file(cs->socket, sr->fd_file,
                                 &sr->bytes_offset, sr->bytes_to_send);

    if (nbytes > 0) {
        if (sr->loop == 0) {
            mk_socket_set_cork_flag(cs->socket, TCP_CORK_OFF);
        }
        sr->bytes_to_send -= nbytes;
    }

    sr->loop++;

    if (nbytes < 0) {
        perror("sendfile");
        return EXIT_ABORT;
    }

    return sr->bytes_to_send;
}