35#define _Class _URLSessionDataTask
52#pragma mark - URLSessionTask
101 if (this->cachedResponse) {
104 this->cachedResponse = NULL;
126 if (this->cachedResponse) {
134 CURLcode code = curl_easy_perform(self->locals.
handle);
140 if (code == CURLE_OK) {
154 if (this->cachedResponse) {
155 switch (this->urlSessionTask.state) {
162 if (this->urlSessionTask.completion) {
183 const uint8_t *bytes = (uint8_t *)
data;
184 const size_t bytesReceived = size * count;
186 if (this->data == NULL) {
192 this->urlSessionTask.bytesReceived += bytesReceived;
193 return bytesReceived;
204 curl_easy_setopt(self->locals.
handle, CURLOPT_WRITEDATA, self);
207#pragma mark - Class lifecycle
234 .name =
"URLSessionDataTask",
238 .interfaceSize =
sizeof(URLSessionDataTaskInterface),
static Object * copy(const Object *self)
static Array * init(Array *self)
static void teardown(void)
Called atexit to teardown Objectively.
static void setup(void)
Called when initializing Object to setup Objectively.
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Class * _initialize(const ClassDef *def)
Initializes the given Class.
#define alloc(type)
Allocate and initialize and instance of type.
#define super(type, obj, method,...)
static void appendBytes(Data *self, const uint8_t *bytes, size_t length)
void * ident
The identity type, similar to Objective-C id.
static void storeCachedResponseForRequest(URLCache *self, const URLRequest *request, const URLResponse *response, const Data *data)
A cache for HTTP responses.
A management context for loading resources via URLs.
Class * _URLSessionDataTask(void)
static size_t writeFunction(char *data, size_t size, size_t count, ident self)
The CURLOPT_WRITEFUNCTION callback.
static void resume(URLSessionTask *self)
static void materializeCachedResponse(URLSessionDataTask *self)
Copies a cached response into this task's live response and data fields.
static void cancel(URLSessionTask *self)
static void cacheResponse(URLSessionDataTask *self)
static void execute(URLSessionTask *self)
static void dealloc(Object *self)
static void initialize(Class *clazz)
Use data tasks to send and receive Data in-memory.
Class * _URLSessionTask(void)
@ URLSESSIONTASK_RESUMING
@ URLSESSIONTASK_CANCELED
@ URLSESSIONTASK_SUSPENDING
@ URLSESSIONTASK_SUSPENDED
@ URLSESSIONTASK_COMPLETED
#define do_once(once, block)
Executes the given block at most one time.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
Object is the root Class of The Objectively Class hierarchy.
A cache for HTTP responses.
URLResponse * response
The HTTP response.
Data * data
The response body.
size_t size
The cached body size.
A protocol-agnostic abstraction for URLSessionTask responses.
int httpStatusCode
The HTTP response status code.
URLCache * urlCache
The cache for URL responses, or NULL to disable caching.
Use data tasks to send and receive Data in-memory.
URLCachedResponse * cachedResponse
A cached response, if this task was fulfilled from URLCache.
Data * data
The data received.
URLSessionTask urlSessionTask
The superclass.
URLSessionConfiguration * configuration
The session configuration.
URL session tasks are handles to pending URL operations.
struct URLResponse * response
The response.
ident handle
The backing libcurl handle.
size_t bytesExpectedToSend
The count of bytes this task expects to send.
struct URLRequest * request
The request.
size_t bytesReceived
The count of bytes received.
struct URLSession * session
The session.
size_t bytesSent
The count of bytes sent.
size_t bytesExpectedToReceive
The count of bytes this task expects to receive.