Ejemplo n.º 1
0
        public DispatchInfo Send(HttpRequest request, Action <HttpResponse> onResponse)
        {
            DispatchInfo info = new DispatchInfo(request, onResponse);

            SendInternal(info);
            return(info);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
             }
         }
     }
 }
Ejemplo n.º 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;
             });
         }
     });
 }
Ejemplo n.º 5
0
 internal CancellationToken(DispatchInfo source)
 {
     this.source = source;
 }
Ejemplo n.º 6
0
 internal WaitForResponse(HttpRequest request)
 {
     this.dispatchInfo = new DispatchInfo(request, SetResponse);
 }
Ejemplo n.º 7
0
 void SendInternal(DispatchInfo info)
 {
     pendingRequests.Enqueue(info);
     TransmitIfPossible();
 }