[Top][All Lists]

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

[libmicrohttpd] How to tell when incoming PUT has arrived in full

From: Mike Durian
Subject: [libmicrohttpd] How to tell when incoming PUT has arrived in full
Date: Wed, 12 Aug 2009 16:06:11 -0600
User-agent: KMail/1.12.0 (FreeBSD/7.2-STABLE; KDE/4.3.0; i386; ; )

I'm writing an application using libmicrohttpd on the server side and libcurl 
on the client side.  The client sends data using PUT to the server which 
stores it in a temporary file until all the data arrives, then processes it an 
generates a reponse.  I've having difficulty determining when all the data has 

Originally, I had planned on using the MHD_RequestCompletedCallback to notify 
my application when all the data has arrived and would generate the HTTP 
response in it.  However, it looks like MHD_RequestCompletedCallback is called 
only after the HTTP response is sent.

My next attempt was to check the "Content-Length" header and use it to 
determine when all the data has arrived.  While this works for determining 
when all the data has been sent to MHD_AccessHandlerCallback, I can't use it 
to tell when I should queue a response.  If I try to enqueue a response as 
soon as all the data has been passed to MHD_AccessHandlerCallback, 
MHD_queue_response fails.  I dug into the MHD_Connection internals and logged 
the amount of data the has been passed to MHD_AccessHandlerCallback and the 
connection state.  Here's what I saw:

state = 4, req_len = 0
state = 6, req_len = 1943
state = 6, req_len = 3886
state = 6, req_len = 5829
state = 6, req_len = 6694
state = 9, req_len = 6694

The 6694 byte request, which is sent in a single TCP packet, is passed to 
MHD_AccessHandlerCallback in a number of chunks.  Then 
MHD_AccessHandlerCallback is called one final time with no new data.  If I try 
to call MHD_queue_response as soon as all the data is available, it fails 
because Connection is still in state MHD_CONNECTION_CONTINUE_SENT.  The final 
time MHD_AccessHandlerCallback is called the Connection is in state 
MHD_CONNECTION_FOOTERS_RECEIVED and MHD_queue_response will succeed.

The problem is, MHD_queue_response is enforcing a pre-condition that the 
application cannot verify.  Namely, the Connection state. I'm not sure how to 
check this without breaking the API.

Can you advise on how I can detect when the complete message has arrived and 
it is safe to enqueue a response?


reply via email to

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