Hello,
I have studied the code in elua_uip.c and I wonder why the following code works: elua_net_size elua_net_recvbuf( int s, luaL_Buffer* buf, elua_net_size maxsize, s16 readto, unsigned timer_id, u32 to_us ) { return elua_net_recv_internal( s, buf, maxsize, readto, timer_id, to_us, 1 ); } The parameter buf is a pointer to luaL_Buffer and this pointer is passed to the function elua_net_recv_internal. elua_net_recv_internal interprets buf as a pointer to a buffer where the received characters are stored into. So the first received character overwrites the first byte in luaL_Buffer, but luaL_Buffer does not start with a buffer but with other data elements: typedef struct luaL_Buffer { char *p; /* current position in buffer */ int lvl; /* number of strings in the stack (level) */ lua_State *L; char buffer[LUAL_BUFFERSIZE]; } luaL_Buffer; I think the correct call should be: elua_net_size elua_net_recvbuf( int s, luaL_Buffer* buf, elua_net_size maxsize, s16 readto, unsigned timer_id, u32 to_us ) { return elua_net_recv_internal( s, buf->buffer, maxsize, readto, timer_id, to_us, 1 ); } Erwin _______________________________________________ Elua-dev mailing list [hidden email] https://lists.berlios.de/mailman/listinfo/elua-dev |
Hello,
Problem solved, I have overlooked the last parameter with_buffer of elua_net_recv_internal. When set to 1, then the buffer is treated as luaL_Buffer in the uip-application. Sorry for inconvenience. Erwin > Hello, > > I have studied the code in elua_uip.c and I wonder why the following > code works: > > elua_net_size elua_net_recvbuf( int s, luaL_Buffer* buf, elua_net_size > maxsize, s16 readto, unsigned timer_id, u32 to_us ) > { > return elua_net_recv_internal( s, buf, maxsize, readto, timer_id, > to_us, 1 ); > } > > The parameter buf is a pointer to luaL_Buffer and this pointer is passed > to the function elua_net_recv_internal. elua_net_recv_internal > interprets buf as a pointer to a buffer where the received characters > are stored into. So the first received character overwrites the first > byte in luaL_Buffer, but luaL_Buffer does not start with a buffer but > with other data elements: > typedef struct luaL_Buffer { > char *p; /* current position in buffer */ > int lvl; /* number of strings in the stack (level) */ > lua_State *L; > char buffer[LUAL_BUFFERSIZE]; > } luaL_Buffer; > > I think the correct call should be: > > elua_net_size elua_net_recvbuf( int s, luaL_Buffer* buf, elua_net_size > maxsize, s16 readto, unsigned timer_id, u32 to_us ) > { > return elua_net_recv_internal( s, buf->buffer, maxsize, readto, > timer_id, to_us, 1 ); > } > > Erwin > > _______________________________________________ > Elua-dev mailing list > [hidden email] > https://lists.berlios.de/mailman/listinfo/elua-dev > > _______________________________________________ Elua-dev mailing list [hidden email] https://lists.berlios.de/mailman/listinfo/elua-dev |
I'm glad you figured it out, as I didn't have time to check that part of the source code, and I was starting to think that we do have a bug there :)
Best, Bogdan On Wed, Dec 2, 2009 at 10:28 PM, erny hombre <[hidden email]> wrote: Hello, _______________________________________________ Elua-dev mailing list [hidden email] https://lists.berlios.de/mailman/listinfo/elua-dev |
Free forum by Nabble | Edit this page |