203 {
204
206
207 self->handle = curl_multi_init();
208 assert(self->handle);
209
210 while (true) {
211 int ret;
212
213 bool idle;
214 synchronized(self->condition, {
216 $(self->condition, wait);
217 }
219 });
220
221 if (idle) {
222 break;
223 }
224
226
228
230
231 bool isExecuting;
232 synchronized(self->condition, {
233 isExecuting = task->isExecuting;
234 });
235
236 if (isExecuting) {
237 continue;
238 }
239
241
242 if (task->handle) {
243 const CURLcode err = curl_easy_pause(task->handle, CURLPAUSE_ALL);
244 assert(err == CURLE_OK);
245 }
246
247 synchronized(self->condition, {
250 }
251 });
252
254
255 if (task->handle == NULL) {
256
258 assert(task->handle);
259
260 const CURLMcode merr = curl_multi_add_handle(self->handle, task->handle);
261 assert(merr == CURLM_OK);
262 } else {
263 const CURLcode err = curl_easy_pause(task->handle, CURLPAUSE_CONT);
264 assert(err == CURLE_OK);
265 }
266
267 synchronized(self->condition, {
270 }
271 });
272
274
275 if (task->handle) {
276 const CURLMcode merr = curl_multi_remove_handle(self->handle, task->handle);
277 assert(merr == CURLM_OK);
278 }
279
280 task->
result = CURLE_ABORTED_BY_CALLBACK;
282
285 }
286
288
289 synchronized(self->condition, {
291 });
293
294 synchronized(self->condition, {
296 });
297 }
298 }
299
300 CURLMcode merr = curl_multi_wait(self->handle, NULL, 0, 0, NULL);
301 assert(merr == CURLM_OK);
302
303 merr = curl_multi_perform(self->handle, &ret);
304 assert(merr == CURLM_OK);
305
306 CURLMsg *message;
307 while ((message = curl_multi_info_read(self->handle, &ret))) {
308
311
313 if (t->handle == message->easy_handle) {
314 task = t;
315 break;
316 }
317 }
318
319 assert(task);
320
321 if (message->msg == CURLMSG_DONE) {
322
323 merr = curl_multi_remove_handle(self->handle, task->handle);
324 assert(merr == CURLM_OK);
325
326 task->
result = message->data.result;
327
328 synchronized(self->condition, {
331 } else {
333 }
334 });
335
337
339
342 }
343
344 if (task->completion) {
345 task->completion(task, success);
346 }
347
349
350 synchronized(self->condition, {
352 });
353 }
354 }
355
357 }
358
359 curl_multi_cleanup(self->handle);
360
361 return NULL;
362}
static void removeObject(Array *self, const ident obj)
static void teardown(void)
Called atexit to teardown Objectively.
static void setup(void)
Called when initializing Object to setup Objectively.
static bool isKindOfClass(const Object *self, const Class *clazz)
static bool hasWork(const URLSession *self)
Checks whether any task needs the run loop.
Class * _URLSessionDataTask(void)
static void cacheResponse(URLSessionDataTask *self)
@ URLSESSIONTASK_RESUMING
@ URLSESSIONTASK_CANCELED
@ URLSESSIONTASK_SUSPENDING
@ URLSESSIONTASK_COMPLETED
@ URLSESSIONTASK_CANCELING
int httpStatusCode
The HTTP response status code.
struct URLResponse * response
The response.
int result
The libcurl result code (CURLcode) of the transfer, 0 on success.
URLSessionTaskCompletion completion
The completion function.