Exemple #1
0
        public DispatchInfo Send(HttpRequest request, Action <HttpResponse> onResponse)
        {
            DispatchInfo info = new DispatchInfo(request, onResponse);

            SendInternal(info);
            return(info);
        }
Exemple #2
0
        internal HttpResponse Send(DispatchInfo info)
        {
            HttpRequest  request  = info.request;
            HttpResponse response = null;
            DateTime     then     = DateTime.Now;

            while (true)
            {
                requestHandler.Prepare(request);

                LogRequest(request);

                response = IsCacheAvailable(request)
                                        ? GetResponseFromCache(request, info.DownloadProgress, info.cancellationToken)
                                        : GetResponseFromSocket(request, info.DownloadProgress, info.cancellationToken);

                response.Duration = DateTime.Now - then;

                LogResponse(response);

                if (IsRedirect(response))
                {
                    request = MakeRedirectRequest(response);
                }
                else
                {
                    break;
                }
            }

            return(response);
        }
Exemple #3
0
 void TransmitIfPossible()
 {
     if (pendingRequests.Count > 0)
     {
         if (ongoingRequests.Count < settings.maxConcurrentRequests)
         {
             DispatchInfo info = pendingRequests.Dequeue();
             if (!info.IsDisposed)
             {
                 ongoingRequests.Add(info);
                 TransmitInWorkerThread(info);
             }
         }
     }
 }
Exemple #4
0
 void TransmitInWorkerThread(DispatchInfo info)
 {
     ThreadPool.QueueUserWorkItem(state => {
         try {
             HttpResponse response = messenger.Send(info);
             ExecuteOnMainThread(() => {
                 ongoingRequests.Remove(info);
                 info.InvokeCallback(response);
                 TransmitIfPossible();
             });
         }
         catch (Exception exception) {
             ExecuteOnMainThread(() => {
                 throw exception;
             });
         }
     });
 }
Exemple #5
0
 internal CancellationToken(DispatchInfo source)
 {
     this.source = source;
 }
 internal WaitForResponse(HttpRequest request)
 {
     this.dispatchInfo = new DispatchInfo(request, SetResponse);
 }
Exemple #7
0
 void SendInternal(DispatchInfo info)
 {
     pendingRequests.Enqueue(info);
     TransmitIfPossible();
 }