diff --git a/app/modules/net.c b/app/modules/net.c index 4b3c311de5..a93bb1dee8 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -20,10 +20,6 @@ static ip_addr_t host_ip; // for dns -#if 0 -static int expose_array(lua_State* L, char *array, unsigned short len); -#endif - #define MAX_SOCKET 5 static int socket_num = 0; static int socket[MAX_SOCKET]; @@ -57,15 +53,6 @@ static void net_server_disconnected(void *arg) // for tcp server only return; if(gL == NULL) return; -#if 0 - char temp[20] = {0}; - c_sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) ); - NODE_DBG("remote "); - NODE_DBG(temp); - NODE_DBG(":"); - NODE_DBG("%d",pesp_conn->proto.tcp->remote_port); - NODE_DBG(" disconnected.\n"); -#endif if(nud->cb_disconnect_ref != LUA_NOREF && nud->self_ref != LUA_NOREF) { lua_rawgeti(gL, LUA_REGISTRYINDEX, nud->cb_disconnect_ref); @@ -146,18 +133,13 @@ static void net_socket_received(void *arg, char *pdata, unsigned short len) return; lua_rawgeti(gL, LUA_REGISTRYINDEX, nud->cb_receive_ref); lua_rawgeti(gL, LUA_REGISTRYINDEX, nud->self_ref); // pass the userdata(server) to callback func in lua - // expose_array(gL, pdata, len); - // *(pdata+len) = 0; - // NODE_DBG(pdata); - // NODE_DBG("\n"); lua_pushlstring(gL, pdata, len); - // lua_pushinteger(gL, len); lua_call(gL, 2, 0); } static void net_socket_sent(void *arg) { - // NODE_DBG("net_socket_sent is called.\n"); + NODE_DBG("net_socket_sent is called.\n"); struct espconn *pesp_conn = arg; if(pesp_conn == NULL) return; @@ -195,26 +177,6 @@ static void net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) NODE_DBG("self_ref null.\n"); return; } -/* original - if(ipaddr == NULL) - { - NODE_ERR( "DNS Fail!\n" ); - goto end; - } - // ipaddr->addr is a uint32_t ip - char ip_str[20]; - c_memset(ip_str, 0, sizeof(ip_str)); - if(ipaddr->addr != 0) - { - c_sprintf(ip_str, IPSTR, IP2STR(&(ipaddr->addr))); - } - - lua_rawgeti(gL, LUA_REGISTRYINDEX, nud->cb_dns_found_ref); // the callback function - //lua_rawgeti(gL, LUA_REGISTRYINDEX, nud->self_ref); // pass the userdata(conn) to callback func in lua - lua_pushstring(gL, ip_str); // the ip para -*/ - - // "enhanced" lua_rawgeti(gL, LUA_REGISTRYINDEX, nud->cb_dns_found_ref); // the callback function lua_rawgeti(gL, LUA_REGISTRYINDEX, nud->self_ref); // pass the userdata(conn) to callback func in lua @@ -233,7 +195,6 @@ static void net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) } lua_pushstring(gL, ip_str); // the ip para } - // "enhanced" end lua_call(gL, 2, 0); @@ -258,16 +219,6 @@ static void net_server_connected(void *arg) // for tcp only if(pesp_conn == NULL) return; -#if 0 - char temp[20] = {0}; - c_sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) ); - NODE_DBG("remote "); - NODE_DBG(temp); - NODE_DBG(":"); - NODE_DBG("%d",pesp_conn->proto.tcp->remote_port); - NODE_DBG(" connected.\n"); -#endif - for(i=0;iself_ref){ // for a server self_ref is NOREF - luaL_unref(L, LUA_REGISTRYINDEX, skt->self_ref); - skt->self_ref = LUA_NOREF; // for a socket, now only var in lua is ref to the userdata - } -#endif lua_settop(L, n); // reset the stack top skt = NULL; } while( isserver && iself_ref){ // for a server self_ref is NOREF - luaL_unref(L, LUA_REGISTRYINDEX, nud->self_ref); - nud->self_ref = LUA_NOREF; // now only var in lua is ref to the userdata - } -#endif return 0; } @@ -1010,16 +943,6 @@ static int net_send( lua_State* L, const char* mt ) return luaL_error( L, "tcp server send not supported" ); } -#if 0 - char temp[20] = {0}; - c_sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) ); - NODE_DBG("remote "); - NODE_DBG(temp); - NODE_DBG(":"); - NODE_DBG("%d",pesp_conn->proto.tcp->remote_port); - NODE_DBG(" sending data.\n"); -#endif - const char *payload = luaL_checklstring( L, 2, &l ); if (l>1460 || payload == NULL) return luaL_error( L, "need <1460 payload" ); @@ -1415,34 +1338,6 @@ static int net_getdnsserver( lua_State* L ) return 1; } -#if 0 -static int net_array_index( lua_State* L ) -{ - char** parray = luaL_checkudata(L, 1, "net.array"); - int index = luaL_checkint(L, 2); - lua_pushnumber(L, (*parray)[index-1]); - return 1; -} - -static int net_array_newindex( lua_State* L ) -{ - char** parray = luaL_checkudata(L, 1, "net.array"); - int index = luaL_checkint(L, 2); - int value = luaL_checkint(L, 3); - (*parray)[index-1] = value; - return 0; -} - -// expose an array to lua, by storing it in a userdata with the array metatable -static int expose_array(lua_State* L, char *array, unsigned short len) { - char** parray = lua_newuserdata(L, len); - *parray = array; - luaL_getmetatable(L, "net.array"); - lua_setmetatable(L, -2); - return 1; -} -#endif - extern const LUA_REG_TYPE tls_cert_map[]; // Module function map @@ -1471,13 +1366,6 @@ static const LUA_REG_TYPE net_socket_map[] = { { LSTRKEY( "__index" ), LROVAL( net_socket_map ) }, { LNILKEY, LNILVAL } }; -#if 0 -static const LUA_REG_TYPE net_array_map[] = { - { LSTRKEY( "__index" ), LFUNCVAL( net_array_index ) }, - { LSTRKEY( "__newindex" ), LFUNCVAL( net_array_newindex ) }, - { LNILKEY, LNILVAL } -}; -#endif static const LUA_REG_TYPE net_dns_map[] = { { LSTRKEY( "setdnsserver" ), LFUNCVAL( net_setdnsserver ) }, @@ -1511,9 +1399,6 @@ int luaopen_net( lua_State *L ) { luaL_rometatable(L, "net.server", (void *)net_server_map); // create metatable for net.server luaL_rometatable(L, "net.socket", (void *)net_socket_map); // create metatable for net.socket - #if 0 - luaL_rometatable(L, "net.array", (void *)net_array_map); // create metatable for net.array - #endif return 0; }