On Sun, May 22, 2011 at 8:14 AM, Dhruv Matani <[email protected]> wrote:
> For example, say rid=10 and rid=11 were sent to the server and the
> server responded back in the correct order. However, the responses
> came in as 11 first and then 10 which means that the client will
> necessarily have to use the rid to re-order the packets. The reason
> for this is that the payload for the packet with rid=10 was much
> higher than that for rid=11 and it took longer for the complete
> response to come in.
>
> This has complicated processing for me, and I think if many people are
> to adopt it, it makes sense to separate the 2 (except if there is a
> really pressing reason to keep them together - such as not mandating
> ACKs).
You'll have to deal with this anyway, or you'd process responses in
the wrong order. It shouldn't be difficult to deal with this with
XHR. In rough pseudocode, it'd look something like this:
requestList = [];
function requestFinished() {
// Check for finished requests.
while(requestList.length > 0) {
// If we havn't yet received a response to the oldest request, stop.
if(!("result" in requestList[0])
return;
// Received a response:
var finishedRequest = requestList.shift();
// ...
}
}
function makeRequest(req) {
request = {};
openXHR(req, {
oncomplete = function(response) {
request.result = response;
requestFinished();
}
});
requestList.push(request);
}
If requestList[1] receives a response before requestList[0], it just
stores the response for later, and requestFinished does nothing. Once
requestList[0] completes, both responses are processed in order.
--
Glenn Maynard