#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "URLSession.h"
#include "URLCache.h"
#include "Data.h"
#include "URLSessionDataTask.h"
Go to the source code of this file.
◆ _Class
◆ _URLSessionDataTask()
| Class * _URLSessionDataTask |
( |
void |
| ) |
|
Definition at line 227 of file URLSessionDataTask.c.
227 {
230
233 .name = "URLSessionDataTask",
236 .interfaceSize = sizeof(URLSessionDataTaskInterface),
238 });
239 });
240
241 return clazz;
242}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
static void initialize(Class *clazz)
Class * _URLSessionTask(void)
#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.
Use data tasks to send and receive Data in-memory.
◆ cacheResponse()
Definition at line 82 of file URLSessionDataTask.c.
82 {
83
85 return;
86 }
87
89 if (cache) {
91 }
92}
static void storeCachedResponseForRequest(URLCache *self, const URLRequest *request, const URLResponse *response, const Data *data)
A cache for HTTP responses.
URLCache * urlCache
The cache for URL responses, or NULL to disable caching.
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.
struct URLResponse * response
The response.
struct URLRequest * request
The request.
struct URLSession * session
The session, which is not retained.
◆ cancel()
- See also
- URLSessionTask::cancel(URLSessionTask *)
Definition at line 97 of file URLSessionDataTask.c.
97 {
98
100
101 if (this->cachedResponse) {
104 this->cachedResponse = NULL;
106 }
107
108 return;
109 }
110
112}
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
#define super(type, obj, method,...)
static void cancel(URLSessionTask *self)
@ URLSESSIONTASK_CANCELED
@ URLSESSIONTASK_COMPLETED
URL session tasks are handles to pending URL operations.
◆ dealloc()
| static void dealloc |
( |
Object * |
self | ) |
|
|
static |
◆ execute()
- See also
- URLSessionTask::execute(URLSessionTask *)
Definition at line 117 of file URLSessionDataTask.c.
117 {
118
120
123 return;
124 }
125
126 if (this->cachedResponse) {
129 return;
130 }
131
133 if (cache) {
135 }
136
138
141 }
142
144}
ident retain(ident obj)
Atomically increment the given Object's reference count.
static void materializeCachedResponse(URLSessionDataTask *self)
Copies a cached response into this task's live response and data fields.
static void execute(URLSessionTask *self)
int result
The libcurl result code (CURLcode) of the transfer, 0 on success.
URLSessionTaskState state
The state.
◆ initialize()
| static void initialize |
( |
Class * |
clazz | ) |
|
|
static |
- See also
- Class::initialize(Class *)
Definition at line 211 of file URLSessionDataTask.c.
211 {
212
214
219
221}
static void setup(void)
Called when initializing Object to setup Objectively.
static void resume(URLSessionTask *self)
static void cacheResponse(URLSessionDataTask *self)
ident interface
The interface of the Class.
◆ materializeCachedResponse()
Copies a cached response into this task's live response and data fields.
Definition at line 57 of file URLSessionDataTask.c.
57 {
58
60 return;
61 }
62
65
68
73
76}
static Object * copy(const Object *self)
URLResponse * response
The HTTP response.
Data * data
The response body.
size_t size
The cached body size.
A protocol-agnostic abstraction for URLSessionTask responses.
size_t bytesExpectedToSend
The count of bytes this task expects to send.
size_t bytesReceived
The count of bytes received.
size_t bytesSent
The count of bytes sent.
size_t bytesExpectedToReceive
The count of bytes this task expects to receive.
◆ resume()
- See also
- URLSessionTask::resume(URLSessionTask *)
Definition at line 149 of file URLSessionDataTask.c.
149 {
150
152
153 if (this->cachedResponse) {
154 switch (this->urlSessionTask.state) {
160
161 if (this->urlSessionTask.completion) {
163 }
164 break;
165 default:
166 break;
167 }
168
169 return;
170 }
171
173}
@ URLSESSIONTASK_RESUMING
@ URLSESSIONTASK_SUSPENDING
@ URLSESSIONTASK_SUSPENDED
◆ setup()
◆ writeFunction()
| static size_t writeFunction |
( |
char * |
data, |
|
|
size_t |
size, |
|
|
size_t |
count, |
|
|
ident |
self |
|
) |
| |
|
static |
The CURLOPT_WRITEFUNCTION callback.
Definition at line 178 of file URLSessionDataTask.c.
178 {
179
181
182 const uint8_t *bytes = (uint8_t *)
data;
183 const size_t bytesReceived = size * count;
184
185 if (this->
data == NULL) {
187 }
188
190
191 this->urlSessionTask.bytesReceived += bytesReceived;
192 return bytesReceived;
193}
static Array * init(Array *self)
#define alloc(type)
Allocate and initialize and instance of type.
static void appendBytes(Data *self, const uint8_t *bytes, size_t length)