Changeset 1431d991f15fe5e02906e85dc4721a1a99f2eeb1

Show
Ignore:
Timestamp:
06/04/08 21:51:48 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1212616308 +0000
git-parent:

[db9f2be897dce90ece1f1f845c102c811a287b74]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1212616308 +0000
Message:

fix pipelining, refs #28

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/lua_noit.c

    rdb9f2be r1431d99  
    215215  cl->read_goal = 0; 
    216216  cl->read_terminator = NULL; 
    217  
    218   if(lua_isnumber(L, 1)) 
     217  fprintf(stderr, "initiating read... (%d bytes buffered)\n", cl->read_sofar); 
     218 
     219  if(lua_isnumber(L, 1)) { 
    219220    cl->read_goal = lua_tointeger(L, 1); 
    220   else 
     221    fprintf(stderr, " read wants %d bytes\n", cl->read_goal); 
     222    if(cl->read_goal <= cl->read_sofar) { 
     223      const char *current_buff; 
     224      int base; 
     225      size_t len; 
     226     i_know_better: 
     227      base = lua_gettop(L); 
     228      /* We have enough, we can service this right here */ 
     229      luaL_pushresult(&cl->inbuff); 
     230      current_buff = lua_tolstring(L, base + 1, &len); 
     231      assert(len == cl->read_sofar); 
     232      lua_pop(L, 1); 
     233      lua_pushlstring(L, current_buff, cl->read_goal); 
     234      cl->read_sofar -= cl->read_goal; 
     235      if(cl->read_sofar) { 
     236        luaL_buffinit(L, &cl->inbuff); 
     237        luaL_addlstring(&cl->inbuff, current_buff + cl->read_goal, 
     238                        cl->read_sofar); 
     239      } 
     240      return 1; 
     241    } 
     242  } 
     243  else { 
    221244    cl->read_terminator = lua_tostring(L, 1); 
     245    fprintf(stderr, " read wants up to [%s]\n", cl->read_terminator); 
     246    if(cl->read_sofar) { 
     247      const char *cp; 
     248      /* Ugh... inernalism */ 
     249      cp = strnstr(cl->inbuff.buffer, cl->read_terminator, cl->read_sofar); 
     250      if(cp) { 
     251        /* Here we matched... and we _know_ that someone actually wants: 
     252         * strlen(cl->read_terminator) + cp - cl->inbuff.buffer bytes... 
     253         * give it to them. 
     254         */ 
     255        cl->read_goal = strlen(cl->read_terminator) + cp - cl->inbuff.buffer; 
     256        cl->read_terminator = NULL; 
     257        assert(cl->read_goal <= cl->read_sofar); 
     258        goto i_know_better; 
     259      } 
     260    } 
     261  } 
    222262 
    223263  e->callback = noit_lua_socket_read_complete;