[Top][All Lists]

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

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

From: Christian Grothoff
Subject: Re: [libmicrohttpd] How to tell when incoming PUT has arrived in full
Date: Mon, 17 Aug 2009 21:44:38 +0200
User-agent: KMail/1.12.0 (Linux/2.6.30-1-686; KDE/4.3.0; i686; ; )

Dear Mike,

The time when you should queue the response is exactly the second time you 
receive a call to your callback function with 0-bytes of additional upload 
data. The very first call (with 0-bytes of upload data) is there for you to 
initialize your internal data structures; this is followed by (possibly many) 
calls with upload data, but always with more than 0-bytes.  Once the client 
has uploaded all of the data, you get one last call with 
"upload_dataa_size==0" at which point you should queue the response.  Note 
that if you are using 'external select', you can choose to not queue a 
response (since your response may not yet be ready) and then the callback will 
be called each time the "MHD_run" function is invoked (until you queue a 

I hope this explains everything, if not, please don't hesitate to ask for 
further clarifications.



> when all the data has arrived.
> 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?
> Thanks,
> mike

reply via email to

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