Exemple #1
0
 internal CancelableReadState(byte[] buffer, int offset, int count,
                              CurlResponseStream responseStream, CancellationToken cancellationToken) :
     base(buffer, offset, count)
 {
     _stream = responseStream;
     _token  = cancellationToken;
 }
Exemple #2
0
 internal CurlResponseMessage(EasyRequest easy)
 {
     Debug.Assert(easy != null, "Expected non-null EasyRequest");
     _easy           = easy;
     _responseStream = new CurlResponseStream(easy);
     RequestMessage  = easy._requestMessage;
     Content         = new StreamContent(_responseStream);
 }
Exemple #3
0
            internal CurlResponseMessage(EasyRequest easy)
            {
                Debug.Assert(easy != null, "Expected non-null EasyRequest");
                RequestMessage = easy._requestMessage;
                ResponseStream = new CurlResponseStream(easy);
                Content        = new StreamContent(ResponseStream);

                // On Windows, we pass the equivalent of the easy._cancellationToken
                // in to StreamContent's ctor.  This in turn passes that token through
                // to ReadAsync operations on the stream response stream when HttpClient
                // reads from the response stream to buffer it with ResponseContentRead.
                // We don't need to do that here in the Unix implementation as, until the
                // SendAsync task completes, the handler will have registered with the
                // CancellationToken with an action that will cancel all work related to
                // the easy handle if cancellation occurs, and that includes canceling any
                // pending reads on the response stream.  It wouldn't hurt anything functionally
                // to still pass easy._cancellationToken here, but it will increase costs
                // a bit, as each read will then need to allocate a larger state object as
                // well as register with and unregister from the cancellation token.
            }
Exemple #4
0
        private unsafe static size_t CurlReceiveBodyCallback(
            byte *buffer,
            size_t size,
            size_t nitems,
            IntPtr context)
        {
            size *= nitems;
            GCHandle gch   = GCHandle.FromIntPtr(context);
            var      state = (RequestCompletionSource)gch.Target;

            try
            {
                // Set task completion after all headers have been received
                // Fail if we find that task is already Canceled or Faulted
                if (state.Task.IsCanceled || state.Task.IsFaulted)
                {
                    // Returing a value other than size fails the callback and forces
                    // request completion with an error
                    return((size > 0) ? size - 1 : 1);
                }
                state.TrySetResult(state.ResponseMessage);

                // Wait for a reader
                // TODO: The below call blocks till all the data has been read since
                //       response body is not suppored to be buffered in memory.
                //       Figure out some way to work around this
                CurlResponseStream contentStream = state.ResponseMessage.ContentStream;
                contentStream.WaitAndSignalReaders(buffer, (long)size);
                return(size);
            }
            catch (Exception ex)
            {
                HandleAsyncException(state, ex);
                // Returing a value other than size fails the callback and forces
                // request completion with an error
                return((size > 0) ? size - 1 : 1);
            }
        }
Exemple #5
0
 internal CancelableReadState(Memory <byte> buffer, CurlResponseStream responseStream, CancellationToken cancellationToken) : base(buffer)
 {
     _stream = responseStream;
     _token  = cancellationToken;
 }
 internal CancelableReadState(Memory <byte> buffer, CurlResponseStream responseStream) : base(buffer)
 {
     _stream = responseStream;
 }