I am a bit puzzled over how to send a file from an http server to a client(web-browser).
First I send the header and my next task is to send the file content. However I want to send it in segments of say 512 bytes instead of the whole file at once as I ran into some problems.
I am a bit lost on how to achieve that. Here is what I want
read file1;
while (seg=get_next_segment(file1)){
do
send(seg)
until (seg_is_sent)
}
However I can't seem to find the appropriate functions to achieve that. fread and fseek crossed through my mind but the first one reads the whole file at once and with fseek I don't see a way to just grab a portion from a file(instead of reading from the file pointer until the end of the file).
freadreads the whole file at once, why does it have parameters telling it how much to read? Andfseekcan't be used for reading at all.sendfileis a lot more efficient.