libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] Handling range requests with libmicrohttpd


From: Christian Grothoff
Subject: Re: [libmicrohttpd] Handling range requests with libmicrohttpd
Date: Wed, 29 Dec 2010 14:12:11 +0100
User-agent: KMail/1.13.5 (Linux/2.6.32-trunk-vserver-amd64; KDE/4.4.5; x86_64; ; )

On Tuesday 28 December 2010 23:18:43 address@hidden wrote:
> Hello,
> 
> I'm using libmicrohttpd as a streaming server that serves audio files to an
> HTML5 Audio object. It's working fine for small files, but for songs that
> are longer and have larger files, the audio object sends a range request
> and because I'm not handling the request properly, the audio object fails.
> I am using MHD_USE_THREAD_PER_CONNECTION in MHD_start_daemon(), and I
> create a response like this:
> 
> response = MHD_create_response_from_callback(sizeof(char)*fileSize, 32 *
> 1024, &file_reader, filePointer, &file_free_callback);
> 
> My file_reader is this:
> 
> static ssize_t file_reader(void *cls, uint64_t pos, char *buffer, size_t
> max) {
>     FILE *fp = (FILE*) cls;
>     (void) fseek(fp, pos, SEEK_SET);
>     return fread(buffer, 1, max, fp);
> }
> 
> When the second request comes in, the first request is still in the process
> of reading and serving the file, and I get this header:
> 
> Range: bytes=127023-
> 
> So what's the proper way of handling a range request? I'm very stuck on
> this and would appreciate any assistance. Thanks.

Simple: *you* need to parse the range request (since, presumably, you set the 
'ranges accepted' header) and then *you* simply add the offset (here 127023) to 
'pos' in your file_reader.  You can pass the connection handle (or just the 
offset) as part of a struct (which should also likely include FILE) as 'cls' to 
the file reader.

Happy hacking,

Christian
p.s.: please do not send HTML-encoded e-mail to the mailinglist



reply via email to

[Prev in Thread] Current Thread [Next in Thread]