#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 228 of file URLSessionDataTask.c.
228 {
231
234 .name = "URLSessionDataTask",
238 .interfaceSize = sizeof(URLSessionDataTaskInterface),
240 });
241 });
242
243 return clazz;
244}
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.
◆ 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
134 CURLcode code = curl_easy_perform(self->locals.
handle);
135
137
139
140 if (code == CURLE_OK) {
142 }
143
145}
static void teardown(void)
Called atexit to teardown Objectively.
static void setup(void)
Called when initializing Object to setup Objectively.
static void materializeCachedResponse(URLSessionDataTask *self)
Copies a cached response into this task's live response and data fields.
static void cacheResponse(URLSessionDataTask *self)
int httpStatusCode
The HTTP response status code.
ident handle
The backing libcurl handle.
◆ initialize()
| static void initialize |
( |
Class * |
clazz | ) |
|
|
static |
- See also
- Class::initialize(Class *)
Definition at line 212 of file URLSessionDataTask.c.
212 {
213
215
220
222}
static void resume(URLSessionTask *self)
static void execute(URLSessionTask *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 150 of file URLSessionDataTask.c.
150 {
151
153
154 if (this->cachedResponse) {
155 switch (this->urlSessionTask.state) {
161
162 if (this->urlSessionTask.completion) {
164 }
165 break;
166 default:
167 break;
168 }
169
170 return;
171 }
172
174}
@ 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 179 of file URLSessionDataTask.c.
179 {
180
182
183 const uint8_t *bytes = (uint8_t *)
data;
184 const size_t bytesReceived = size * count;
185
186 if (this->
data == NULL) {
188 }
189
191
192 this->urlSessionTask.bytesReceived += bytesReceived;
193 return bytesReceived;
194}
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)