[Reconnoiter-devel] [reconnoiter commit] r866 - trunk/src/modules

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Fri Sep 18 20:51:57 EDT 2009


Author: jesus
Date: 2009-09-18 20:51:57 -0400 (Fri, 18 Sep 2009)
New Revision: 866

Modified:
   trunk/src/modules/lua_noit.c
Log:
refactored incorrectly. one sweeps, one doesn't, refs #181

Modified: trunk/src/modules/lua_noit.c
===================================================================
--- trunk/src/modules/lua_noit.c	2009-09-19 00:27:44 UTC (rev 865)
+++ trunk/src/modules/lua_noit.c	2009-09-19 00:51:57 UTC (rev 866)
@@ -244,9 +244,9 @@
 noit_lua_socket_do_read(eventer_t e, int *mask, struct nl_slcl *cl,
                         int *read_complete) {
   char buff[4096];
-  int len = 0;
+  int len;
   *read_complete = 0;
-  do {
+  while((len = e->opset->read(e->fd, buff, sizeof(buff), mask, e)) > 0) {
     if(cl->read_goal) {
       int remaining = cl->read_goal - cl->read_sofar;
       /* copy up to the goal into the inbuff */
@@ -283,7 +283,7 @@
         break;
       }
     }
-  } while((len = e->opset->read(e->fd, buff, sizeof(buff), mask, e)) > 0);
+  }
   return len;
 }
 static int
@@ -337,13 +337,39 @@
 
   if(lua_isnumber(L, 2)) {
     cl->read_goal = lua_tointeger(L, 2);
-    if(cl->read_goal == 0) {
-      lua_pushstring(L, "");
+    if(cl->read_goal <= cl->read_sofar) {
+      int base;
+     i_know_better:
+      base = lua_gettop(L);
+      /* We have enough, we can service this right here */
+      lua_pushlstring(L, cl->inbuff, cl->read_goal);
+      cl->read_sofar -= cl->read_goal;
+      if(cl->read_sofar) {
+        memmove(cl->inbuff, cl->inbuff + cl->read_goal, cl->read_sofar);
+      }
+      cl->inbuff_len = cl->read_sofar;
       return 1;
     }
   }
-  else
+  else {
     cl->read_terminator = lua_tostring(L, 2);
+    if(cl->read_sofar) {
+      const char *cp;
+      /* Ugh... inernalism */
+      cp = strnstrn(cl->read_terminator, strlen(cl->read_terminator),
+                    cl->inbuff, cl->read_sofar);
+      if(cp) {
+        /* Here we matched... and we _know_ that someone actually wants:
+         * strlen(cl->read_terminator) + cp - cl->inbuff.buffer bytes...
+         * give it to them.
+         */
+        cl->read_goal = strlen(cl->read_terminator) + cp - cl->inbuff;
+        cl->read_terminator = NULL;
+        assert(cl->read_goal <= cl->read_sofar);
+        goto i_know_better;
+      }
+    }
+  }
 
   len = noit_lua_socket_do_read(e, &mask, cl, &args);
   if(args == 1) return 1; /* completed read, return result */



More information about the Reconnoiter-devel mailing list