gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11858 - in gnunet: . src/include src/util


From: gnunet
Subject: [GNUnet-SVN] r11858 - in gnunet: . src/include src/util
Date: Tue, 22 Jun 2010 09:22:50 +0200

Author: grothoff
Date: 2010-06-22 09:22:50 +0200 (Tue, 22 Jun 2010)
New Revision: 11858

Modified:
   gnunet/TODO
   gnunet/src/include/gnunet_server_lib.h
   gnunet/src/util/server_mst.c
Log:
refine API to make it usable for server itself

Modified: gnunet/TODO
===================================================================
--- gnunet/TODO 2010-06-21 21:42:07 UTC (rev 11857)
+++ gnunet/TODO 2010-06-22 07:22:50 UTC (rev 11858)
@@ -5,11 +5,6 @@
 * TRANSPORT:
   - HTTP backend [MW]
 * DV: [Nate]
-  - write DV API (need to move declarations from dv_api.c to 
gnunet_dv_service.h!)
-  - implement DV service 
-  - implement DV library (looks done)
-  - implement DV transport plugin
-  - implement testcases 
   - implement performance tests (needs tbench)
 * UTIL:
   - only connect() sockets that are ready (select()) [Nils]

Modified: gnunet/src/include/gnunet_server_lib.h
===================================================================
--- gnunet/src/include/gnunet_server_lib.h      2010-06-21 21:42:07 UTC (rev 
11857)
+++ gnunet/src/include/gnunet_server_lib.h      2010-06-22 07:22:50 UTC (rev 
11858)
@@ -657,16 +657,38 @@
  * @param size number of bytes in buf
  * @param purge should any excess bytes in the buffer be discarded 
  *       (i.e. for packet-based services like UDP)
- * @return GNUNET_NO if the data stream is corrupt 
- *         GNUNET_SYSERR if the data stream is corrupt beyond repair
+ * @param one_shot only call callback once, keep rest of message in buffer
+ * @return GNUNET_OK if we are done processing (need more data)
+ *         GNUNET_NO if one_shot was set and we have another message ready
+ *         GNUNET_SYSERR if the data stream is corrupt
  */
 int
 GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
                           const char *buf,
                           size_t size,
-                          int purge);
+                          int purge,
+                          int one_shot);
 
+
 /**
+ * Read incoming data into the receive buffer and call the
+ * callback for all complete messages.
+ *
+ * @param mst tokenizer to use
+ * @param sock socket to read from (must be ready according to select)
+ * @param purge should any excess bytes in the buffer be discarded 
+ *       (i.e. for packet-based services like UDP)
+ * @return GNUNET_NO if the data stream is corrupt 
+ *         GNUNET_SYSERR if the data stream is corrupt beyond repair
+ */
+int
+GNUNET_SERVER_mst_read (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
+                       const char *buf,
+                       size_t size,
+                       int purge);
+
+
+/**
  * Destroys a tokenizer.
  *
  * @param mst tokenizer to destroy

Modified: gnunet/src/util/server_mst.c
===================================================================
--- gnunet/src/util/server_mst.c        2010-06-21 21:42:07 UTC (rev 11857)
+++ gnunet/src/util/server_mst.c        2010-06-22 07:22:50 UTC (rev 11858)
@@ -92,14 +92,17 @@
  * @param size number of bytes in buf
  * @param purge should any excess bytes in the buffer be discarded 
  *       (i.e. for packet-based services like UDP)
- * @return GNUNET_NO if the data stream is corrupt 
- *         GNUNET_SYSERR if the data stream is corrupt beyond repair
+ * @param one_shot only call callback once, keep rest of message in buffer
+ * @return GNUNET_OK if we are done processing (need more data)
+ *         GNUNET_NO if one_shot was set and we have another message ready
+ *         GNUNET_SYSERR if the data stream is corrupt
  */
 int
 GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
                           const char *buf,
                           size_t size,
-                          int purge)
+                          int purge,
+                          int one_shot)
 {
   const struct GNUNET_MessageHeader *hdr;
   size_t delta;
@@ -107,7 +110,9 @@
   char *ibuf;
   int need_align;
   unsigned long offset;
+  int ret;
 
+  ret = GNUNET_OK;
   ibuf = (char*) &mst->hdr;
   if (mst->off > 0)
     {
@@ -133,8 +138,6 @@
       if (want < sizeof (struct GNUNET_MessageHeader))
        {
          GNUNET_break_op (0);
-         if (purge)
-           return GNUNET_NO;
          return GNUNET_SYSERR;
        }
       if (want < mst->off)
@@ -154,6 +157,13 @@
            mst->off = 0;    
          return GNUNET_OK;
        }
+      if (one_shot == GNUNET_SYSERR)
+       {
+         ret = GNUNET_NO;
+         goto copy;
+       }
+      if (one_shot == GNUNET_YES)
+       one_shot = GNUNET_SYSERR;
       mst->cb (mst->cb_cls, mst->client_identity, &mst->hdr);
       mst->off = 0;
     }
@@ -174,6 +184,13 @@
          want = ntohs (hdr->size);
          if (size < want)
            break; /* or not, buffer incomplete... */
+         if (one_shot == GNUNET_SYSERR)
+           {
+             ret = GNUNET_NO;
+             goto copy;
+           }
+         if (one_shot == GNUNET_YES)
+           one_shot = GNUNET_SYSERR;
          mst->cb (mst->cb_cls, mst->client_identity, hdr);
          buf += want;
          size -= want;
@@ -184,15 +201,16 @@
          goto do_align;
        }
     }
+ copy:
   if ( (size > 0) && (! purge) )
     {
-      memcpy (&mst->hdr, buf, size);
-      mst->off = size;
+      memcpy (&ibuf[mst->off], buf, size);
+      mst->off += size;
       size = 0;
     }
   if (purge)
     mst->off = 0;    
-  return GNUNET_OK;
+  return ret;
 }
 
 




reply via email to

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