aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_client.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-08-27 13:03:18 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-08-27 13:03:18 +0000
commit989004864aeac327d250fc99a125a675f387e64f (patch)
tree209d87b769643708febddc84a232678e44268efd /src/transport/plugin_transport_http_client.c
parentf02419d0d0a3d81eaed5dddc001ae82359c88120 (diff)
downloadgnunet-989004864aeac327d250fc99a125a675f387e64f.tar.gz
gnunet-989004864aeac327d250fc99a125a675f387e64f.zip
more
Diffstat (limited to 'src/transport/plugin_transport_http_client.c')
-rw-r--r--src/transport/plugin_transport_http_client.c93
1 files changed, 66 insertions, 27 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index b04c3f47a..1f0c4dab7 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -278,6 +278,32 @@ client_reschedule_session_timeout (struct Session *s);
278static void 278static void
279client_stop_session_timeout (struct Session *s); 279client_stop_session_timeout (struct Session *s);
280 280
281/**
282 * Function setting up file descriptors and scheduling task to run
283 *
284 * @param plugin plugin as closure
285 * @param now schedule task in 1ms, regardless of what curl may say
286 * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok
287 */
288static int
289client_schedule (struct HTTP_Client_Plugin *plugin, int now);
290
291
292int
293client_exist_session (struct HTTP_Client_Plugin *plugin, struct Session *s)
294{
295 struct Session * head;
296
297 GNUNET_assert (NULL != plugin);
298 GNUNET_assert (NULL != s);
299
300 for (head = plugin->head; head != NULL; head = head->next)
301 {
302 if (head == s)
303 return GNUNET_YES;
304 }
305 return GNUNET_NO;
306}
281 307
282/** 308/**
283 * Function that can be used by the transport service to transmit 309 * Function that can be used by the transport service to transmit
@@ -315,15 +341,45 @@ http_client_plugin_send (void *cls,
315 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 341 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
316{ 342{
317 struct HTTP_Client_Plugin *plugin = cls; 343 struct HTTP_Client_Plugin *plugin = cls;
318 int bytes_sent = 0; 344 struct HTTP_Message *msg;
345 size_t res = -1;
319 346
320 GNUNET_assert (plugin != NULL); 347 GNUNET_assert (plugin != NULL);
321 GNUNET_assert (session != NULL); 348 GNUNET_assert (session != NULL);
322 349
323 GNUNET_break (0); 350 /* lookup if session is really existing */
351 if (GNUNET_YES != client_exist_session (plugin, session))
352 {
353 GNUNET_break (0);
354 return GNUNET_SYSERR;
355 }
356
357 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, session->plugin->name,
358 "Sending message with %u to peer `%s' with session %p\n",
359 msgbuf_size, GNUNET_i2s (&session->target), session);
360
361 /* create new message and schedule */
362 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
363 msg->next = NULL;
364 msg->size = msgbuf_size;
365 msg->pos = 0;
366 msg->buf = (char *) &msg[1];
367 msg->transmit_cont = cont;
368 msg->transmit_cont_cls = cont_cls;
369 memcpy (msg->buf, msgbuf, msgbuf_size);
370 GNUNET_CONTAINER_DLL_insert_tail (session->msg_head, session->msg_tail, msg);
371
372 if (session->client_put_paused == GNUNET_YES)
373 {
374 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, session->plugin->name,
375 "Session %p was suspended, unpausing\n", session->client_put);
376 session->client_put_paused = GNUNET_NO;
377 curl_easy_pause (session->client_put, CURLPAUSE_CONT);
378 }
379 client_schedule (session->plugin, GNUNET_YES);
380 client_reschedule_session_timeout (session);
324 381
325 /* struct Plugin *plugin = cls; */ 382 return res;
326 return bytes_sent;
327} 383}
328 384
329 385
@@ -358,22 +414,6 @@ client_lookup_session (struct HTTP_Client_Plugin *plugin,
358 return NULL; 414 return NULL;
359} 415}
360 416
361static int
362client_exist_session (struct HTTP_Client_Plugin *plugin, struct Session *s)
363{
364 struct Session * head;
365
366 GNUNET_assert (NULL != plugin);
367 GNUNET_assert (NULL != s);
368
369 for (head = plugin->head; head != NULL; head = head->next)
370 {
371 if (head == s)
372 return GNUNET_YES;
373 }
374 return GNUNET_NO;
375}
376
377/** 417/**
378 * Callback method used with libcurl 418 * Callback method used with libcurl
379 * Method is called when libcurl needs to read data during sending 419 * Method is called when libcurl needs to read data during sending
@@ -637,8 +677,8 @@ client_disconnect (struct Session *s)
637 if (s->client_put != NULL) 677 if (s->client_put != NULL)
638 { 678 {
639 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 679 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
640 "Client: %p / %p Deleting outbound PUT session to peer `%s'\n", 680 "Disconnecting PUT session %p to peer `%s'\n",
641 s, s->client_put, GNUNET_i2s (&s->target)); 681 s, GNUNET_i2s (&s->target));
642 682
643 /* remove curl handle from multi handle */ 683 /* remove curl handle from multi handle */
644 mret = curl_multi_remove_handle (plugin->curl_multi_handle, s->client_put); 684 mret = curl_multi_remove_handle (plugin->curl_multi_handle, s->client_put);
@@ -661,10 +701,9 @@ client_disconnect (struct Session *s)
661 701
662 if (s->client_get != NULL) 702 if (s->client_get != NULL)
663 { 703 {
664 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 704 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
665 "Client: %p / %p Deleting outbound GET session to peer `%s'\n", 705 "Disconnecting GET session %p to peer `%s'\n",
666 s, 706 s, GNUNET_i2s (&s->target));
667 s->client_get, GNUNET_i2s (&s->target));
668 707
669 /* remove curl handle from multi handle */ 708 /* remove curl handle from multi handle */
670 mret = curl_multi_remove_handle (plugin->curl_multi_handle, s->client_get); 709 mret = curl_multi_remove_handle (plugin->curl_multi_handle, s->client_get);
@@ -692,7 +731,7 @@ client_disconnect (struct Session *s)
692 plugin->cur_connections -= 2; 731 plugin->cur_connections -= 2;
693 plugin->env->session_end (plugin->env->cls, &s->target, s); 732 plugin->env->session_end (plugin->env->cls, &s->target, s);
694 733
695 GNUNET_assert (plugin->cur_connections > 0); 734 GNUNET_assert (plugin->cur_connections >= 0);
696 plugin->cur_connections --; 735 plugin->cur_connections --;
697 GNUNET_STATISTICS_set (plugin->env->stats, 736 GNUNET_STATISTICS_set (plugin->env->stats,
698 "# HTTP client connections", 737 "# HTTP client connections",