summaryrefslogtreecommitdiff
path: root/src/curl/curl_reschedule.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/curl/curl_reschedule.c')
-rw-r--r--src/curl/curl_reschedule.c119
1 files changed, 59 insertions, 60 deletions
diff --git a/src/curl/curl_reschedule.c b/src/curl/curl_reschedule.c
index 354ba13df..0fdaa5e1f 100644
--- a/src/curl/curl_reschedule.c
+++ b/src/curl/curl_reschedule.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2015, 2016 GNUnet e.V. 3 Copyright (C) 2015, 2016 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file curl/curl_reschedule.c 21 * @file curl/curl_reschedule.c
22 * @brief API for event loop integration with GNUnet SCHEDULER. 22 * @brief API for event loop integration with GNUnet SCHEDULER.
@@ -28,15 +28,14 @@
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29 29
30extern void * 30extern void *
31GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, 31GNUNET_CURL_download_get_result_(struct GNUNET_CURL_DownloadBuffer *db,
32 CURL *eh, 32 CURL *eh,
33 long *response_code); 33 long *response_code);
34 34
35/** 35/**
36 * Closure for #GNUNET_CURL_gnunet_scheduler_reschedule(). 36 * Closure for #GNUNET_CURL_gnunet_scheduler_reschedule().
37 */ 37 */
38struct GNUNET_CURL_RescheduleContext 38struct GNUNET_CURL_RescheduleContext {
39{
40 /** 39 /**
41 * Just the task. 40 * Just the task.
42 */ 41 */
@@ -66,13 +65,13 @@ struct GNUNET_CURL_RescheduleContext
66 * @return closure for #GNUNET_CURL_gnunet_scheduler_reschedule(). 65 * @return closure for #GNUNET_CURL_gnunet_scheduler_reschedule().
67 */ 66 */
68struct GNUNET_CURL_RescheduleContext * 67struct GNUNET_CURL_RescheduleContext *
69GNUNET_CURL_gnunet_rc_create_with_parser (struct GNUNET_CURL_Context *ctx, 68GNUNET_CURL_gnunet_rc_create_with_parser(struct GNUNET_CURL_Context *ctx,
70 GNUNET_CURL_RawParser rp, 69 GNUNET_CURL_RawParser rp,
71 GNUNET_CURL_ResponseCleaner rc) 70 GNUNET_CURL_ResponseCleaner rc)
72{ 71{
73 struct GNUNET_CURL_RescheduleContext *rctx; 72 struct GNUNET_CURL_RescheduleContext *rctx;
74 73
75 rctx = GNUNET_new (struct GNUNET_CURL_RescheduleContext); 74 rctx = GNUNET_new(struct GNUNET_CURL_RescheduleContext);
76 rctx->ctx = ctx; 75 rctx->ctx = ctx;
77 rctx->parser = rp; 76 rctx->parser = rp;
78 rctx->cleaner = rc; 77 rctx->cleaner = rc;
@@ -87,9 +86,9 @@ GNUNET_CURL_gnunet_rc_create_with_parser (struct GNUNET_CURL_Context *ctx,
87 * @param response the (JSON) response to clean. 86 * @param response the (JSON) response to clean.
88 */ 87 */
89static void 88static void
90clean_result (void *response) 89clean_result(void *response)
91{ 90{
92 json_decref (response); 91 json_decref(response);
93} 92}
94 93
95/** 94/**
@@ -99,11 +98,11 @@ clean_result (void *response)
99 * @return closure for #GNUNET_CURL_gnunet_scheduler_reschedule(). 98 * @return closure for #GNUNET_CURL_gnunet_scheduler_reschedule().
100 */ 99 */
101struct GNUNET_CURL_RescheduleContext * 100struct GNUNET_CURL_RescheduleContext *
102GNUNET_CURL_gnunet_rc_create (struct GNUNET_CURL_Context *ctx) 101GNUNET_CURL_gnunet_rc_create(struct GNUNET_CURL_Context *ctx)
103{ 102{
104 struct GNUNET_CURL_RescheduleContext *rc; 103 struct GNUNET_CURL_RescheduleContext *rc;
105 104
106 rc = GNUNET_new (struct GNUNET_CURL_RescheduleContext); 105 rc = GNUNET_new(struct GNUNET_CURL_RescheduleContext);
107 rc->ctx = ctx; 106 rc->ctx = ctx;
108 rc->parser = &GNUNET_CURL_download_get_result_; 107 rc->parser = &GNUNET_CURL_download_get_result_;
109 rc->cleaner = &clean_result; 108 rc->cleaner = &clean_result;
@@ -117,11 +116,11 @@ GNUNET_CURL_gnunet_rc_create (struct GNUNET_CURL_Context *ctx)
117 * @param rc context to destroy 116 * @param rc context to destroy
118 */ 117 */
119void 118void
120GNUNET_CURL_gnunet_rc_destroy (struct GNUNET_CURL_RescheduleContext *rc) 119GNUNET_CURL_gnunet_rc_destroy(struct GNUNET_CURL_RescheduleContext *rc)
121{ 120{
122 if (NULL != rc->task) 121 if (NULL != rc->task)
123 GNUNET_SCHEDULER_cancel (rc->task); 122 GNUNET_SCHEDULER_cancel(rc->task);
124 GNUNET_free (rc); 123 GNUNET_free(rc);
125} 124}
126 125
127 126
@@ -131,7 +130,7 @@ GNUNET_CURL_gnunet_rc_destroy (struct GNUNET_CURL_RescheduleContext *rc)
131 * @param cls a `struct GNUNET_CURL_RescheduleContext *` 130 * @param cls a `struct GNUNET_CURL_RescheduleContext *`
132 */ 131 */
133static void 132static void
134context_task (void *cls) 133context_task(void *cls)
135{ 134{
136 struct GNUNET_CURL_RescheduleContext *rc = cls; 135 struct GNUNET_CURL_RescheduleContext *rc = cls;
137 long timeout; 136 long timeout;
@@ -145,36 +144,36 @@ context_task (void *cls)
145 144
146 rc->task = NULL; 145 rc->task = NULL;
147 146
148 GNUNET_CURL_perform2 (rc->ctx, rc->parser, rc->cleaner); 147 GNUNET_CURL_perform2(rc->ctx, rc->parser, rc->cleaner);
149 max_fd = -1; 148 max_fd = -1;
150 timeout = -1; 149 timeout = -1;
151 FD_ZERO (&read_fd_set); 150 FD_ZERO(&read_fd_set);
152 FD_ZERO (&write_fd_set); 151 FD_ZERO(&write_fd_set);
153 FD_ZERO (&except_fd_set); 152 FD_ZERO(&except_fd_set);
154 GNUNET_CURL_get_select_info (rc->ctx, 153 GNUNET_CURL_get_select_info(rc->ctx,
155 &read_fd_set, 154 &read_fd_set,
156 &write_fd_set, 155 &write_fd_set,
157 &except_fd_set, 156 &except_fd_set,
158 &max_fd, 157 &max_fd,
159 &timeout); 158 &timeout);
160 if (timeout >= 0) 159 if (timeout >= 0)
161 delay = 160 delay =
162 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, timeout); 161 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, timeout);
163 else 162 else
164 delay = GNUNET_TIME_UNIT_FOREVER_REL; 163 delay = GNUNET_TIME_UNIT_FOREVER_REL;
165 rs = GNUNET_NETWORK_fdset_create (); 164 rs = GNUNET_NETWORK_fdset_create();
166 GNUNET_NETWORK_fdset_copy_native (rs, &read_fd_set, max_fd + 1); 165 GNUNET_NETWORK_fdset_copy_native(rs, &read_fd_set, max_fd + 1);
167 ws = GNUNET_NETWORK_fdset_create (); 166 ws = GNUNET_NETWORK_fdset_create();
168 GNUNET_NETWORK_fdset_copy_native (ws, &write_fd_set, max_fd + 1); 167 GNUNET_NETWORK_fdset_copy_native(ws, &write_fd_set, max_fd + 1);
169 if (NULL == rc->task) 168 if (NULL == rc->task)
170 rc->task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 169 rc->task = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
171 delay, 170 delay,
172 rs, 171 rs,
173 ws, 172 ws,
174 &context_task, 173 &context_task,
175 rc); 174 rc);
176 GNUNET_NETWORK_fdset_destroy (rs); 175 GNUNET_NETWORK_fdset_destroy(rs);
177 GNUNET_NETWORK_fdset_destroy (ws); 176 GNUNET_NETWORK_fdset_destroy(ws);
178} 177}
179 178
180 179
@@ -188,13 +187,13 @@ context_task (void *cls)
188 * (pointer to a pointer!) 187 * (pointer to a pointer!)
189 */ 188 */
190void 189void
191GNUNET_CURL_gnunet_scheduler_reschedule (void *cls) 190GNUNET_CURL_gnunet_scheduler_reschedule(void *cls)
192{ 191{
193 struct GNUNET_CURL_RescheduleContext *rc = *(void **) cls; 192 struct GNUNET_CURL_RescheduleContext *rc = *(void **)cls;
194 193
195 if (NULL != rc->task) 194 if (NULL != rc->task)
196 GNUNET_SCHEDULER_cancel (rc->task); 195 GNUNET_SCHEDULER_cancel(rc->task);
197 rc->task = GNUNET_SCHEDULER_add_now (&context_task, rc); 196 rc->task = GNUNET_SCHEDULER_add_now(&context_task, rc);
198} 197}
199 198
200/* end of curl_reschedule.c */ 199/* end of curl_reschedule.c */