aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_client.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-09-15 09:31:18 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-09-15 09:31:18 +0000
commitc2a2296221c174ae68fb82f3373a5594391474cb (patch)
tree53a284d9e0fcb274712f3d551bcdb00c1223d062 /src/transport/plugin_transport_http_client.c
parentd0cdb1cc4a8d030fd106475e1bbc520c7486fc24 (diff)
downloadgnunet-c2a2296221c174ae68fb82f3373a5594391474cb.tar.gz
gnunet-c2a2296221c174ae68fb82f3373a5594391474cb.zip
more functionality
Diffstat (limited to 'src/transport/plugin_transport_http_client.c')
-rw-r--r--src/transport/plugin_transport_http_client.c125
1 files changed, 121 insertions, 4 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index 9a5d4b261..41300285a 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -96,6 +96,116 @@ client_send (struct Session *s, const char *msgbuf, size_t msgbuf_size)
96 return GNUNET_OK; 96 return GNUNET_OK;
97} 97}
98 98
99/**
100 * Task performing curl operations
101 * @param cls plugin as closure
102 * @param tc gnunet scheduler task context
103 */
104static void
105client_perform (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
106
107/**
108 * Function setting up file descriptors and scheduling task to run
109 *
110 * @param plugin plugin as closure
111 * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok
112 */
113static int
114client_schedule_next_perform (struct Plugin *plugin)
115{
116 fd_set rs;
117 fd_set ws;
118 fd_set es;
119 int max;
120 struct GNUNET_NETWORK_FDSet *grs;
121 struct GNUNET_NETWORK_FDSet *gws;
122 long to;
123 CURLMcode mret;
124 struct GNUNET_TIME_Relative timeout;
125
126 /* Cancel previous scheduled task */
127 if (plugin->client_perform_task!= GNUNET_SCHEDULER_NO_TASK)
128 {
129 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
130 plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
131 }
132
133 max = -1;
134 FD_ZERO (&rs);
135 FD_ZERO (&ws);
136 FD_ZERO (&es);
137 mret = curl_multi_fdset (plugin->client_mh, &rs, &ws, &es, &max);
138 if (mret != CURLM_OK)
139 {
140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
141 "curl_multi_fdset", __FILE__, __LINE__,
142 curl_multi_strerror (mret));
143 return GNUNET_SYSERR;
144 }
145 mret = curl_multi_timeout (plugin->client_mh, &to);
146 if (to == -1)
147 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5);
148 else
149 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to);
150 if (mret != CURLM_OK)
151 {
152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
153 "curl_multi_timeout", __FILE__, __LINE__,
154 curl_multi_strerror (mret));
155 return GNUNET_SYSERR;
156 }
157
158 grs = GNUNET_NETWORK_fdset_create ();
159 gws = GNUNET_NETWORK_fdset_create ();
160 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
161 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
162 plugin->client_perform_task =
163 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
164 GNUNET_SCHEDULER_NO_TASK,
165 timeout,
166 grs,
167 gws,
168 &client_perform,
169 plugin);
170 GNUNET_NETWORK_fdset_destroy (gws);
171 GNUNET_NETWORK_fdset_destroy (grs);
172 return GNUNET_OK;
173}
174
175
176/**
177 * Task performing curl operations
178 * @param cls plugin as closure
179 * @param tc gnunet scheduler task context
180 */
181static void
182client_perform (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
183{
184 struct Plugin *plugin = cls;
185 static unsigned int handles_last_run;
186 int running;
187 CURLMcode mret;
188
189 GNUNET_assert (cls != NULL);
190
191 plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
192 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
193 return;
194 do
195 {
196 running = 0;
197 mret = curl_multi_perform (plugin->client_mh, &running);
198 if ((running < handles_last_run) && (running > 0))
199 {
200
201 }
202 //curl_handle_finished (plugin);
203 handles_last_run = running;
204 }
205 while (mret == CURLM_CALL_MULTI_PERFORM);
206 client_schedule_next_perform (plugin);
207}
208
99int 209int
100client_connect (struct Session *s) 210client_connect (struct Session *s)
101{ 211{
@@ -138,10 +248,10 @@ client_connect (struct Session *s)
138 //curl_easy_setopt (s->client_get, CURLOPT_READDATA, ps); 248 //curl_easy_setopt (s->client_get, CURLOPT_READDATA, ps);
139 //curl_easy_setopt (s->client_get, CURLOPT_WRITEFUNCTION, curl_receive_cb); 249 //curl_easy_setopt (s->client_get, CURLOPT_WRITEFUNCTION, curl_receive_cb);
140 //curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, ps); 250 //curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, ps);
141 curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT, 251 curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT_MS,
142 (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); 252 (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
143 //curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, ps); 253 //curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, ps);
144 curl_easy_setopt (s->client_get, CURLOPT_CONNECTTIMEOUT, 254 curl_easy_setopt (s->client_get, CURLOPT_CONNECTTIMEOUT_MS,
145 (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value); 255 (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value);
146 curl_easy_setopt (s->client_get, CURLOPT_BUFFERSIZE, 256 curl_easy_setopt (s->client_get, CURLOPT_BUFFERSIZE,
147 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE); 257 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
@@ -169,10 +279,10 @@ client_connect (struct Session *s)
169 //curl_easy_setopt (s->client_put, CURLOPT_READDATA, ps); 279 //curl_easy_setopt (s->client_put, CURLOPT_READDATA, ps);
170 //curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, curl_receive_cb); 280 //curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, curl_receive_cb);
171 //curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, ps); 281 //curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, ps);
172 curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT, 282 curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT_MS,
173 (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); 283 (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
174 //curl_easy_setopt (s->client_put, CURLOPT_PRIVATE, ps); 284 //curl_easy_setopt (s->client_put, CURLOPT_PRIVATE, ps);
175 curl_easy_setopt (s->client_put, CURLOPT_CONNECTTIMEOUT, 285 curl_easy_setopt (s->client_put, CURLOPT_CONNECTTIMEOUT_MS,
176 (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value); 286 (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value);
177 curl_easy_setopt (s->client_put, CURLOPT_BUFFERSIZE, 287 curl_easy_setopt (s->client_put, CURLOPT_BUFFERSIZE,
178 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE); 288 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
@@ -201,6 +311,7 @@ client_connect (struct Session *s)
201 } 311 }
202 312
203 /* Perform connect */ 313 /* Perform connect */
314 s->plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_perform, s->plugin);
204 315
205 return res; 316 return res;
206} 317}
@@ -227,6 +338,12 @@ client_start (struct Plugin *plugin)
227void 338void
228client_stop (struct Plugin *plugin) 339client_stop (struct Plugin *plugin)
229{ 340{
341 if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
342 {
343 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
344 plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
345 }
346
230 curl_multi_cleanup (plugin->client_mh); 347 curl_multi_cleanup (plugin->client_mh);
231 curl_global_cleanup (); 348 curl_global_cleanup ();
232} 349}