[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Send big file with libevent http module



On Tue, Jan 31, 2017 at 6:48 PM, Viallard Anthony <viallard@xxxxxxxxx> wrote:
> On Tue, 31 Jan 2017 15:26:24 +0100
> Reindl Harald <h.reindl@xxxxxxxxxxxxx> wrote:
>
>> normally large static files should not make it to the memory at all
>> https://linux.die.net/man/2/sendfile
>>
>
> Hi Harald,
>
> Actually, I send the file in a "multipart/form-data" http message
> because I need to send other informations at the same time. So, I fill
> an evbuffer with differents values and the file separated by a
> delimiter. I open the file and I read/write 5KB to the evbuffer.
>
> Therefore, I don't think I use sendfile() and this is why I have this
> memory problem. Maybe if I use an other kind of http message instead of
> "multipart/form-data", put the values from the http body to the query
> string and use the function evbuffer_add_file(), I can hope not having
> this issue ?

To make sendfile() works in libevent you should use draining to fd[1]
since you need encode the file (or add headers). So indeed you can
read file by chunks and add it to output buffer
(evbuffer_add_file_segment()) if it's length is not greater them 100KB
(or smth like this)

[1] https://github.com/libevent/libevent/blob/ffbce578c40a06491ce6585ab2d82ebb69a52d30/buffer.c#L3191
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.