cleaning up set handlers, eliminating 2nd level demultiplexing and improving use...
[oweals/gnunet.git] / src / transport / plugin_transport_http_client.c
index 262961a29746fb8653a94c133cf417c97e2dc59b..ceed94af8b2d700e7ddd7bdcde231364bd593e57 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     Copyright (C) 2002-2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2002-2014 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -226,17 +226,17 @@ struct GNUNET_ATS_Session
   /**
    * Session timeout task
    */
-  struct GNUNET_SCHEDULER_Task * put_disconnect_task;
+  struct GNUNET_SCHEDULER_Task *put_disconnect_task;
 
   /**
    * Session timeout task
    */
-  struct GNUNET_SCHEDULER_Task * timeout_task;
+  struct GNUNET_SCHEDULER_Task *timeout_task;
 
   /**
    * Task to wake up client receive handle when receiving is allowed again
    */
-  struct GNUNET_SCHEDULER_Task * recv_wakeup_task;
+  struct GNUNET_SCHEDULER_Task *recv_wakeup_task;
 
   /**
    * Absolute time when to receive data again.
@@ -557,8 +557,7 @@ client_reschedule_session_timeout (struct GNUNET_ATS_Session *s)
  * @param tc gnunet scheduler task context
  */
 static void
-client_run (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc);
+client_run (void *cls);
 
 
 /**
@@ -682,7 +681,7 @@ client_log (CURL *curl,
     ttype = "UNSPECIFIED";
     break;
   }
-  memcpy (text, data, size);
+  GNUNET_memcpy (text, data, size);
   if (text[size - 1] == '\n')
   {
     text[size] = '\0';
@@ -775,7 +774,7 @@ http_client_plugin_send (void *cls,
   msg->buf = (char *) &msg[1];
   msg->transmit_cont = cont;
   msg->transmit_cont_cls = cont_cls;
-  memcpy (msg->buf,
+  GNUNET_memcpy (msg->buf,
           msgbuf,
           msgbuf_size);
   GNUNET_CONTAINER_DLL_insert_tail (s->msg_head,
@@ -997,11 +996,9 @@ client_lookup_session (struct HTTP_Client_Plugin *plugin,
  * is the delayed task that actually disconnects the PUT.
  *
  * @param cls the `struct GNUNET_ATS_Session *` with the put
- * @param tc scheduler context
  */
 static void
-client_put_disconnect (void *cls,
-                       const struct GNUNET_SCHEDULER_TaskContext *tc)
+client_put_disconnect (void *cls)
 {
   struct GNUNET_ATS_Session *s = cls;
 
@@ -1064,8 +1061,10 @@ client_send_cb (void *stream,
          "Session %p/request %p: nothing to send, suspending\n",
          s,
          s->put.easyhandle);
-    s->put_disconnect_task = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT,
-        &client_put_disconnect, s);
+    s->put_disconnect_task
+      = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT,
+                                     &client_put_disconnect,
+                                     s);
     s->put.state = H_PAUSED;
     return CURL_READFUNC_PAUSE;
   }
@@ -1074,7 +1073,9 @@ client_send_cb (void *stream,
   /* calculate how much fits in buffer */
   len = GNUNET_MIN (msg->size - msg->pos,
                     size * nmemb);
-  memcpy (stream, &msg->buf[msg->pos], len);
+  GNUNET_memcpy (stream,
+                &msg->buf[msg->pos],
+                len);
   msg->pos += len;
   if (msg->pos == msg->size)
   {
@@ -1128,17 +1129,13 @@ client_send_cb (void *stream,
  * Wake up a curl handle which was suspended
  *
  * @param cls the session
- * @param tc task context
  */
 static void
-client_wake_up (void *cls,
-                const struct GNUNET_SCHEDULER_TaskContext *tc)
+client_wake_up (void *cls)
 {
   struct GNUNET_ATS_Session *s = cls;
 
   s->recv_wakeup_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Session %p/request %p: Waking up GET handle\n",
        s, s->get.easyhandle);
@@ -1293,11 +1290,9 @@ client_receive (void *stream,
  * Task performing curl operations
  *
  * @param cls plugin as closure
- * @param tc scheduler task context
  */
 static void
-client_run (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc)
+client_run (void *cls)
 {
   struct HTTP_Client_Plugin *plugin = cls;
   int running;
@@ -1308,9 +1303,6 @@ client_run (void *cls,
   int msgs_left;
 
   plugin->client_perform_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-
   /* While data are available or timeouts occured */
   do
   {
@@ -1963,11 +1955,9 @@ http_client_plugin_get_network_for_address (void *cls,
  * Session was idle, so disconnect it
  *
  * @param cls the `struct GNUNET_ATS_Session` of the idle session
- * @param tc scheduler context
  */
 static void
-client_session_timeout (void *cls,
-                        const struct GNUNET_SCHEDULER_TaskContext *tc)
+client_session_timeout (void *cls)
 {
   struct GNUNET_ATS_Session *s = cls;
   struct GNUNET_TIME_Relative left;
@@ -2384,8 +2374,10 @@ http_client_plugin_update_inbound_delay (void *cls,
   if (s->recv_wakeup_task != NULL)
   {
     GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
-    s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delay,
-        &client_wake_up, s);
+    s->recv_wakeup_task
+      = GNUNET_SCHEDULER_add_delayed (delay,
+                                     &client_wake_up,
+                                     s);
   }
 }