private bool sendBatch(BatchRequest batch) { if (batch.Length <= 0) { //something wrong o_O log.Error("Unexpected call"); //XXX exit here?? } BatchedListener combinedRequestListener = new BatchedListener(this); BatchedRequest combinedRequest = new BatchedRequest(this); /* find the first request to be sent: it provides the server address and the request name for the whole combined request */ RequestObjects first = null; while (first == null && batch.Length > 0) { first = batch.shift(); if (first.tutor.shouldBeSent()) { combinedRequest.Server = first.request.TargetServer; combinedRequest.RequestName = first.request.RequestName; combinedRequest.add(first.request); combinedRequestListener.add(first.listener); ongoingRequests.AddLast(first); } else { first.tutor.notifyAbort(); first = null; } } if (combinedRequest.length() == 0) { //nothing to send return(false); } /* add the other requests to the combined request: they share the server address and the request name */ while ((requestLimit == 0 || (combinedRequest.length() + batch.NextRequestLength) < requestLimit) && batch.Length > 0) { RequestObjects next = batch.shift(); if (next.tutor.shouldBeSent()) { combinedRequest.add(next.request); combinedRequestListener.add(next.listener); ongoingRequests.AddLast(next); } else { next.tutor.notifyAbort(); } } activeConnection = transport.sendRequest(protocol, combinedRequest, combinedRequestListener, options.HttpExtraHeadersOnSessionCreationOnly ? null : options.HttpExtraHeaders, options.Proxy, options.TCPConnectTimeout, options.TCPReadTimeout); return(true); }
public Task TryEnqueue(IRequest request, TimeSpan timeout) { BatchedRequest bt; lock (_requestQueue) { if (_executionCompleted) { return null; } _requestQueue.Enqueue(bt = new BatchedRequest(request, timeout)); } return bt.ResultTask; }
public Task TryEnqueue(IRequest request, CancellationToken token = new CancellationToken()) { BatchedRequest bt; lock (_requestQueue) { if (_executionCompleted) { return null; } _requestQueue.Enqueue(bt = new BatchedRequest(request, token)); } return bt.ResultTask; }