1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00

Workaround for bug related to remote server handle getting GC'd. Solution may

not clean itself up in all failure cases, however.  Current approach could
likely be replaced with central table that could handle dispatching for
multiple concurrent connections.
This commit is contained in:
James Snyder 2009-06-30 02:58:52 +00:00
parent 67f782f057
commit e006aaaaa9
5 changed files with 23 additions and 13 deletions

View File

@ -1,7 +1,7 @@
import os, sys import os, sys
output = 'lua' output = 'lua'
cdefs = '-DLUA_CROSS_COMPILER -DLUA_REMOTE' cdefs = '-DLUA_CROSS_COMPILER -DLUA_REMOTE -DLUA_USE_READLINE'
# Lua source files and include path # Lua source files and include path
lua_files = """lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lua_files = """lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c
@ -13,7 +13,7 @@ local_include = "-Isrc/lua -Iinc -Isrc/modules"
# Compiler/linker options # Compiler/linker options
cccom = "gcc -g %s -Wall %s -c $SOURCE -o $TARGET" % ( local_include, cdefs ) cccom = "gcc -g %s -Wall %s -c $SOURCE -o $TARGET" % ( local_include, cdefs )
linkcom = "gcc -o $TARGET $SOURCES -lm" linkcom = "gcc -o $TARGET $SOURCES -lm -lreadline"
# Env for building the program # Env for building the program
comp = Environment( CCCOM = cccom, comp = Environment( CCCOM = cccom,

View File

@ -89,13 +89,13 @@
//## Modified for eLua //## Modified for eLua
//## Defaults search modules path to our ROM File System //## Defaults search modules path to our ROM File System
#ifndef LUA_REMOTE
#define LUA_PATH_DEFAULT "/rom/?.lua" #define LUA_PATH_DEFAULT "/rom/?.lua"
/* #else
** ## Original LUA_PATH_DEFAULT
#define LUA_PATH_DEFAULT \ #define LUA_PATH_DEFAULT \
".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua" LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua"
*/ #endif
#define LUA_CPATH_DEFAULT \ #define LUA_CPATH_DEFAULT \
".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
@ -103,12 +103,15 @@
#define LUA_ROOT "/usr/local/" #define LUA_ROOT "/usr/local/"
#define LUA_LDIR LUA_ROOT "share/lua/5.1/" #define LUA_LDIR LUA_ROOT "share/lua/5.1/"
#define LUA_CDIR LUA_ROOT "lib/lua/5.1/" #define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
#ifndef LUA_REMOTE
#define LUA_PATH_DEFAULT "/rom/?.lua" #define LUA_PATH_DEFAULT "/rom/?.lua"
/* #else
#define LUA_PATH_DEFAULT \ #define LUA_PATH_DEFAULT \
"./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua" LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"
*/ #endif
#define LUA_CPATH_DEFAULT \ #define LUA_CPATH_DEFAULT \
"./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so" "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
#endif #endif

View File

@ -59,7 +59,7 @@ void transport_open( Transport *tpt, const char *path )
options.c_cflag &= ~CSIZE; options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8; options.c_cflag |= CS8;
options.c_cc[VMIN] = 0; options.c_cc[VMIN] = 1;
options.c_cc[VTIME] = 10; options.c_cc[VTIME] = 10;
tcsetattr(tpt->fd, TCSANOW, &options); tcsetattr(tpt->fd, TCSANOW, &options);

View File

@ -1535,12 +1535,19 @@ static int rpc_dispatch( lua_State *L )
static int rpc_server( lua_State *L ) static int rpc_server( lua_State *L )
{ {
int shref;
ServerHandle *handle = rpc_listen_helper( L ); ServerHandle *handle = rpc_listen_helper( L );
/* hack to anchor handle in registry */
/* @@@ this should be replaced when we create a system for multiple connections */
/* @@@ such a mechanism would likely likely create a table for multiple connections that we could service in an event loop */
shref = luaL_ref( L, LUA_REGISTRYINDEX );
lua_rawgeti(L, LUA_REGISTRYINDEX, shref );
while ( transport_is_open( &handle->ltpt ) ) while ( transport_is_open( &handle->ltpt ) )
rpc_dispatch_helper( L, handle ); rpc_dispatch_helper( L, handle );
printf( "LT: %d, AT: %d\n", handle->ltpt.fd, handle->atpt.fd ); luaL_unref( L, LUA_REGISTRYINDEX, shref );
server_handle_destroy( handle ); server_handle_destroy( handle );
return 0; return 0;
} }

View File

@ -4,8 +4,8 @@ end
rpc.on_error (error_handler); rpc.on_error (error_handler);
-- slave,err = rpc.connect ("/dev/tty.usbserial-ftCYPMYJ"); slave,err = rpc.connect ("/dev/tty.usbserial-ftCYPMYJ");
slave,err = rpc.connect("/dev/tty.usbserial-04110857B") -- slave,err = rpc.connect("/dev/tty.usbserial-04110857B")
--slave,err = rpc.connect ("/dev/ttys0"); --slave,err = rpc.connect ("/dev/ttys0");
print("Platform: " .. slave.pd.platform()) print("Platform: " .. slave.pd.platform())