Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Macros | Functions
URLSessionDataTask.c File Reference
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "MutableData.h"
#include "URLSessionDataTask.h"

Go to the source code of this file.

Macros

#define _Class   _URLSessionDataTask
 
#define CURL_WRITEFUNC_ABORT   0
 

Functions

Class_URLSessionDataTask (void)
 
static void dealloc (Object *self)
 
static void initialize (Class *clazz)
 
static void setup (URLSessionTask *self)
 
static size_t writeFunction (char *data, size_t size, size_t count, ident self)
 The CURLOPT_WRITEFUNCTION callback. More...
 

Macro Definition Documentation

◆ _Class

#define _Class   _URLSessionDataTask

Definition at line 32 of file URLSessionDataTask.c.

◆ CURL_WRITEFUNC_ABORT

#define CURL_WRITEFUNC_ABORT   0

Definition at line 50 of file URLSessionDataTask.c.

Function Documentation

◆ _URLSessionDataTask()

Class * _URLSessionDataTask ( void  )

Definition at line 99 of file URLSessionDataTask.c.

99 {
100 static Class *clazz;
101 static Once once;
102
103 do_once(&once, {
104 clazz = _initialize(&(const ClassDef) {
105 .name = "URLSessionDataTask",
106 .superclass = _URLSessionTask(),
107 .instanceSize = sizeof(URLSessionDataTask),
108 .interfaceOffset = offsetof(URLSessionDataTask, interface),
109 .interfaceSize = sizeof(URLSessionDataTaskInterface),
111 });
112 });
113
114 return clazz;
115}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
static void initialize(Class *clazz)
long Once
The Once type.
Definition: Once.h:37
#define do_once(once, block)
Executes the given block at most one time.
Definition: Once.h:43
ClassDefs are passed to _initialize via an archetype to initialize a Class.
Definition: Class.h:41
The runtime representation of a Class.
Definition: Class.h:95
Use data tasks to send and receive Data in-memory.
Class * _URLSessionTask(void)
The URLSessionTask archetype.

◆ dealloc()

static void dealloc ( Object self)
static
See also
Object::dealloc(Object *)

Definition at line 39 of file URLSessionDataTask.c.

39 {
40
42
43 release(this->data);
44
45 super(Object, self, dealloc);
46}
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Definition: Class.c:196
#define super(type, obj, method,...)
MutableData * data(void)
Returns a new MutableData.
Definition: MutableData.c:75
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46
void dealloc(Object *self)
Frees all resources held by this Object.
Definition: Array.c:50

◆ initialize()

static void initialize ( Class clazz)
static
See also
Class::initialize(Class *)

Definition at line 88 of file URLSessionDataTask.c.

88 {
89
90 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
91
92 ((URLSessionTaskInterface *) clazz->interface)->setup = setup;
93}
ident interface
The interface of the Class.
Definition: Class.h:105
void setup(URLSessionTask *)
Sets up this task.

◆ setup()

static void setup ( URLSessionTask self)
static
See also
URLSessionTask::setup(URLSessionTask *)

Definition at line 75 of file URLSessionDataTask.c.

75 {
76
78
79 curl_easy_setopt(self->locals.handle, CURLOPT_WRITEFUNCTION, writeFunction);
80 curl_easy_setopt(self->locals.handle, CURLOPT_WRITEDATA, self);
81}
static size_t writeFunction(char *data, size_t size, size_t count, ident self)
The CURLOPT_WRITEFUNCTION callback.
URL session tasks are handles to pending URL operations.
ident handle
The backing libcurl handle.

◆ writeFunction()

static size_t writeFunction ( char *  data,
size_t  size,
size_t  count,
ident  self 
)
static

The CURLOPT_WRITEFUNCTION callback.

Definition at line 55 of file URLSessionDataTask.c.

55 {
56
58
59 const uint8_t *bytes = (uint8_t *) data;
60 const size_t bytesReceived = size * count;
61
62 if (this->data == NULL) {
63 this->data = (Data *) $(alloc(MutableData), init);
64 }
65
66 $((MutableData *) this->data, appendBytes, bytes, bytesReceived);
67
68 this->urlSessionTask.bytesReceived += bytesReceived;
69 return bytesReceived;
70}
#define alloc(type)
Allocate and initialize and instance of type.
Definition: Class.h:159
Condition * init(Condition *self)
Initializes this Condition.
Definition: Condition.c:67
Immutable data buffers.
Definition: Data.h:50
Mutable data buffers.
Definition: MutableData.h:40
void appendBytes(MutableData *self, const uint8_t *bytes, size_t length)
Appends the given bytes to this Data.
Definition: MutableData.c:53