gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r11555 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r11555 - gnunet/src/transport
Date: Mon, 31 May 2010 09:53:21 +0200

Author: wachs
Date: 2010-05-31 09:53:21 +0200 (Mon, 31 May 2010)
New Revision: 11555

Modified:
   gnunet/src/transport/plugin_transport_http.c
Log:


Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c        2010-05-30 18:20:12 UTC 
(rev 11554)
+++ gnunet/src/transport/plugin_transport_http.c        2010-05-31 07:53:21 UTC 
(rev 11555)
@@ -290,13 +290,32 @@
 }
 
 /**
+ * Finds a http session in our linked list using libcurl handle as a key
+ * Needed when sending data with libcurl to differentiate between sessions
+ * @param peer peeridentity
+ * @return http session corresponding to peer identity
+ */
+static struct Session * find_session_by_curlhandle( CURL* handle )
+{
+  struct Session * cur;
+
+  cur = plugin->sessions;
+  while (cur != NULL)
+  {
+    if ( handle == cur->curl_handle )
+      return cur;
+    cur = plugin->sessions->next;
+  }
+  return NULL;
+}
+
+/**
  * Create a new session
  *
  * @param address address the peer is using
  * @peer  peer identity
  * @return created session object
  */
-
 static struct Session * create_session (struct sockaddr_in *address, const 
struct GNUNET_PeerIdentity *peer)
 {
   struct sockaddr_in  *addrin;
@@ -354,12 +373,10 @@
                       const struct sockaddr *addr, socklen_t addr_len)
 {
   /* Every connection is accepted, nothing more to do here */
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connect!\n");
   return MHD_YES;
 }
 
 
-
 /**
  * Process GET or PUT request received via MHD.  For
  * GET, queue response that will send back our pending
@@ -623,9 +640,8 @@
  * Call MHD to process pending requests and then go back
  * and schedule the next run.
  */
-static void
-http_daemon_run (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void http_daemon_run (void *cls,
+                             const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct MHD_Daemon *daemon_handle = cls;
 
@@ -638,8 +654,6 @@
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
     return;
 
-
-
   GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
   if (daemon_handle == http_daemon_v4)
     http_task_v4 = http_daemon_prepare (daemon_handle);
@@ -650,6 +664,9 @@
 
 /**
  * Removes a message from the linked list of messages
+ * @param ses session to remove message from
+ * @param msg message to remove
+ * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success
  */
 
 static int remove_http_message(struct Session * ses, struct HTTP_Message * msg)
@@ -688,6 +705,15 @@
 }
 
 
+/**
+ * Callback method used with libcurl
+ * Method is called when libcurl needs to read data during sending
+ * @param stream pointer where to write data
+ * @param size_t size of an individual element
+ * @param nmemb count of elements that can be written to the buffer
+ * @param ptr source pointer, passed to the libcurl handle
+ * @return bytes written to stream
+ */
 static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void 
*ptr)
 {
   struct Session * ses = ptr;
@@ -708,12 +734,20 @@
   return bytes_sent;
 }
 
-
-static size_t send_write_callback( void *ptr, size_t size, size_t nmemb, void 
*stream)
+/**
+* Callback method used with libcurl
+* Method is called when libcurl needs to write data during sending
+* @param stream pointer where to write data
+* @param size_t size of an individual element
+* @param nmemb count of elements that can be written to the buffer
+* @param ptr destination pointer, passed to the libcurl handle
+* @return bytes read from stream
+*/
+static size_t send_write_callback( void *stream, size_t size, size_t nmemb, 
void *ptr)
 {
   char * data = malloc(size*nmemb +1);
 
-  memcpy( data, ptr, size*nmemb);
+  memcpy( data, stream, size*nmemb);
   data[size*nmemb] = '\0';
   /* Just a dummy print for the response recieved for the PUT message */
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recieved %u bytes: `%s' \n", size * 
nmemb, data);
@@ -722,8 +756,18 @@
 
 }
 
+/**
+ * Function setting up file descriptors and scheduling task to run
+ * @param ses session to send data to
+ * @return bytes sent to peer
+ */
 static size_t send_prepare(struct Session* session );
 
+/**
+ * Function setting up curl handle and selecting message to send
+ * @param ses session to send data to
+ * @return bytes sent to peer
+ */
 static ssize_t send_select_init (struct Session* ses  )
 {
   char * url;
@@ -769,7 +813,7 @@
   int running;
   struct CURLMsg *msg;
   CURLMcode mret;
-  struct Session * cs = cls;
+  struct Session * cs = NULL;
 
   http_task_send = GNUNET_SCHEDULER_NO_TASK;
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -779,7 +823,6 @@
     {
       running = 0;
       mret = curl_multi_perform (multi_handle, &running);
-      //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"send_execute %u\n", running);
       if (running == 0)
         {
           do
@@ -789,11 +832,17 @@
               GNUNET_break (msg != NULL);
               if (msg == NULL)
                 break;
+              /* get session for affected curl handle */
+              cs = find_session_by_curlhandle (msg->easy_handle);
+              GNUNET_assert ( cs != NULL );
               switch (msg->msg)
                 {
+
                 case CURLMSG_DONE:
                   if ( (msg->data.result != CURLE_OK) &&
                        (msg->data.result != CURLE_GOT_NOTHING) )
+                    {
+
                     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
                                _("%s failed for `%s' at %s:%d: `%s'\n"),
                                "curl_multi_perform",
@@ -801,6 +850,8 @@
                                __FILE__,
                                __LINE__,
                                curl_easy_strerror (msg->data.result));
+                    /* sending msg failed*/
+                    }
                   else
                     {
                     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -832,6 +883,11 @@
 }
 
 
+/**
+ * Function setting up file descriptors and scheduling task to run
+ * @param ses session to send data to
+ * @return bytes sent to peer
+ */
 static size_t send_prepare(struct Session* session )
 {
   fd_set rs;
@@ -843,7 +899,6 @@
   long to;
   CURLMcode mret;
 
-//  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"send_prepare\n");
   max = -1;
   FD_ZERO (&rs);
   FD_ZERO (&ws);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]