30#define _Class _URLSession
43 $(this->locals.thread,
join, NULL);
45 release(this->locals.condition);
52#pragma mark - URLSession
62 synchronized(self->locals.
lock, {
142 self->locals.
handle = curl_multi_init();
143 assert(self->locals.
handle);
164 if (task->locals.
handle) {
165 const CURLcode err = curl_easy_pause(task->locals.
handle, CURLPAUSE_ALL);
166 assert(err == CURLE_OK);
173 if (task->locals.
handle == NULL) {
176 assert(task->locals.
handle);
178 const CURLMcode merr = curl_multi_add_handle(self->locals.
handle, task->locals.
handle);
179 assert(merr == CURLM_OK);
181 const CURLcode err = curl_easy_pause(task->locals.
handle, CURLPAUSE_CONT);
182 assert(err == CURLE_OK);
189 if (task->locals.
handle) {
190 const CURLMcode merr = curl_multi_remove_handle(self->locals.
handle, task->locals.
handle);
191 assert(merr == CURLM_OK);
202 synchronized(self->locals.
lock, {
207 synchronized(self->locals.
lock, {
213 CURLMcode merr = curl_multi_wait(self->locals.
handle, NULL, 0, 0, NULL);
214 assert(merr == CURLM_OK);
216 merr = curl_multi_perform(self->locals.
handle, &ret);
217 assert(merr == CURLM_OK);
220 while ((message = curl_multi_info_read(self->locals.
handle, &ret))) {
226 if (t->locals.
handle == message->easy_handle) {
234 if (message->msg == CURLMSG_DONE) {
236 merr = curl_multi_remove_handle(self->locals.
handle, task->locals.
handle);
237 assert(merr == CURLM_OK);
249 synchronized(self->locals.
lock, {
258 curl_multi_cleanup(self->locals.
handle);
269 assert(configuration);
335 synchronized(self->locals.
lock, {
351#pragma mark - Class lifecycle
371 const CURLcode code = curl_global_init(CURL_GLOBAL_ALL);
372 assert(code == CURLE_OK);
382 curl_global_cleanup();
395 .name =
"URLSession",
398 .interfaceOffset = offsetof(
URLSession, interface),
399 .interfaceSize =
sizeof(URLSessionInterface),
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.
ident retain(ident obj)
Atomically increment the given Object's reference count.
#define alloc(type)
Allocate and initialize and instance of type.
#define super(type, obj, method,...)
void * ident
The identity type, similar to Objective-C id.
static void destroy(Class *clazz)
static ident taskWithRequest(URLSession *self, ident task, URLRequest *request, URLSessionTaskCompletion completion)
URLSessionTask factory function.
static ident run(Thread *thread)
ThreadFunction for a URLSession.
static URLSession * _sharedInstance
static void initialize(Class *clazz)
A management context for loading resources via URLs.
@ URLSESSIONTASK_RESUMING
@ URLSESSIONTASK_CANCELED
@ URLSESSIONTASK_SUSPENDING
@ URLSESSIONTASK_SUSPENDED
@ URLSESSIONTASK_COMPLETED
@ URLSESSIONTASK_CANCELING
void(* URLSessionTaskCompletion)(URLSessionTask *task, _Bool success)
A function pointer for URLSessionTask completion.
#define do_once(once, block)
Executes the given block at most one time.
ident objectAtIndex(const Array *self, int index)
size_t count
The count of elements.
Array * arrayWithArray(const Array *array)
Returns a new Array containing the contents of array.
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.
POSIX Threads conditional variables.
void wait(Condition *self)
Waits indefinitely for this Condition to be signaled.
Condition * init(Condition *self)
Initializes this Condition.
void signal(Condition *self)
Signals a single Thread waiting on this Condition.
Log * sharedInstance(void)
void addObject(MutableArray *self, const ident obj)
Adds the specified Object to this MutableArray.
void removeObject(MutableArray *self, const ident obj)
Removes the specified Object from this MutableArray.
MutableArray * array(void)
Returns a new MutableArray.
Object is the root Class of The Objectively Class hierarchy.
Class * _Object(void)
The Object archetype.
Object * init(Object *self)
Initializes this Object.
void dealloc(Object *self)
Frees all resources held by this Object.
void start(Operation *self)
Starts this Operation.
void cancel(Operation *self)
Cancels this Operation, allowing it to complete immediately.
Operation * initWithFunction(Operation *self, OperationFunction function, ident data)
Initializes a synchronous Operation with the given function.
void join(Thread *self, ident *status)
Wait for the specified Thread to terminate.
_Bool isCancelled
true when this Thread has been cancelled, false otherwise.
Uniform Resource Locators (RFC 3986).
A protocol-agnostic abstraction for requesting resources via URLs.
URLRequest * initWithURL(URLRequest *self, URL *url)
Initializes this URLRequest with the specified URL.
int httpStatusCode
The HTTP response status code.
Configuration bundle for URLSession.
Use data tasks to send and receive Data in-memory.
Use download tasks to save remote resources to file.
A management context for loading resources via URLs.
URLSessionDataTask * dataTaskWithURL(URLSession *, URL *, URLSessionTaskCompletion)
Creates a URLSessionDataTask for the given URL.
URLSessionDataTask * dataTaskWithRequest(URLSession *, URLRequest *, URLSessionTaskCompletion)
Creates a URLSessionDataTask for the given URLRequest.
URLSessionDownloadTask * downloadTaskWithURL(URLSession *, URL *, URLSessionTaskCompletion)
Creates a URLSessionDownloadTask for the given URL.
Lock * lock
The Lock guarding access to tasks.
Condition * condition
The condition.
URLSessionConfiguration * configuration
The session configuration.
Class * _URLSession(void)
The URLSession archetype.
Thread * thread
The backing Thread.
MutableArray * tasks
The URLSessionTasks.
void invalidateAndCancel(URLSession *)
Invalidates this URLSession and cancels all pending tasks.
URLSession * initWithConfiguration(URLSession *, URLSessionConfiguration *)
Initializes this URLSession with the given configuration.
URLSessionUploadTask * uploadTaskWithRequest(URLSession *, URLRequest *, URLSessionTaskCompletion)
Creates a URLSessionUploadTask for the given URLRequest.
Array * tasks(const URLSession *)
URLSessionDownloadTask * downloadTaskWithRequest(URLSession *, URLRequest *, URLSessionTaskCompletion)
Creates a URLSessionDownloadTask for the given URLRequest.
ident handle
The libcurl handle.
URL session tasks are handles to pending URL operations.
URLSessionTask * initWithRequestInSession(URLSessionTask *, struct URLRequest *, struct URLSession *, URLSessionTaskCompletion)
Initializes this task with the given URLRequest.
struct URLResponse * response
The response.
ident handle
The backing libcurl handle.
void setup(URLSessionTask *)
Sets up this task.
void teardown(URLSessionTask *)
Tears down this task.
URLSessionTaskState state
The state.
URLSessionTaskCompletion completion
The completion function.
Use upload tasks to send files directly from disk.