Removed useless checks before calling luaL_unref
This commit is contained in:
parent
426e805c43
commit
ab950ff518
|
@ -125,11 +125,9 @@ static void mqtt_socket_disconnected(void *arg) // tcp only
|
|||
mud->pesp_conn = NULL;
|
||||
}
|
||||
|
||||
if(mud->self_ref != LUA_NOREF){ // TODO: should we unref the client and delete it?
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->self_ref);
|
||||
mud->self_ref = LUA_NOREF; // unref this, and the mqtt.socket userdata will delete it self
|
||||
}
|
||||
}
|
||||
|
||||
if(call_back){
|
||||
lua_call(L, 1, 0);
|
||||
|
@ -832,35 +830,21 @@ static int mqtt_delete( lua_State* L )
|
|||
// -------
|
||||
|
||||
// free (unref) callback ref
|
||||
if(LUA_NOREF!=mud->cb_connect_ref){
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_connect_ref);
|
||||
mud->cb_connect_ref = LUA_NOREF;
|
||||
}
|
||||
if(LUA_NOREF!=mud->cb_connect_fail_ref){
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_connect_fail_ref);
|
||||
mud->cb_connect_fail_ref = LUA_NOREF;
|
||||
}
|
||||
if(LUA_NOREF!=mud->cb_disconnect_ref){
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_disconnect_ref);
|
||||
mud->cb_disconnect_ref = LUA_NOREF;
|
||||
}
|
||||
if(LUA_NOREF!=mud->cb_message_ref){
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_message_ref);
|
||||
mud->cb_message_ref = LUA_NOREF;
|
||||
}
|
||||
if(LUA_NOREF!=mud->cb_suback_ref){
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_suback_ref);
|
||||
mud->cb_suback_ref = LUA_NOREF;
|
||||
}
|
||||
if(LUA_NOREF!=mud->cb_puback_ref){
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_puback_ref);
|
||||
mud->cb_puback_ref = LUA_NOREF;
|
||||
}
|
||||
lua_gc(L, LUA_GCSTOP, 0);
|
||||
if(LUA_NOREF!=mud->self_ref){
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->self_ref);
|
||||
mud->self_ref = LUA_NOREF;
|
||||
}
|
||||
lua_gc(L, LUA_GCRESTART, 0);
|
||||
NODE_DBG("leave mqtt_delete.\n");
|
||||
return 0;
|
||||
|
@ -1069,7 +1053,6 @@ static int mqtt_socket_connect( lua_State* L )
|
|||
// call back function when a connection is obtained, tcp only
|
||||
if ((stack<=top) && (lua_type(L, stack) == LUA_TFUNCTION || lua_type(L, stack) == LUA_TLIGHTFUNCTION)){
|
||||
lua_pushvalue(L, stack); // copy argument (func) to the top of stack
|
||||
if(mud->cb_connect_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_connect_ref);
|
||||
mud->cb_connect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
stack++;
|
||||
|
@ -1078,14 +1061,12 @@ static int mqtt_socket_connect( lua_State* L )
|
|||
// call back function when a connection fails
|
||||
if ((stack<=top) && (lua_type(L, stack) == LUA_TFUNCTION || lua_type(L, stack) == LUA_TLIGHTFUNCTION)){
|
||||
lua_pushvalue(L, stack); // copy argument (func) to the top of stack
|
||||
if(mud->cb_connect_fail_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_connect_fail_ref);
|
||||
mud->cb_connect_fail_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
stack++;
|
||||
}
|
||||
|
||||
lua_pushvalue(L, 1); // copy userdata to the top of stack
|
||||
if(mud->self_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->self_ref);
|
||||
mud->self_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
|
||||
|
@ -1191,15 +1172,12 @@ static int mqtt_socket_on( lua_State* L )
|
|||
lua_pushvalue(L, 3); // copy argument (func) to the top of stack
|
||||
|
||||
if( sl == 7 && c_strcmp(method, "connect") == 0){
|
||||
if(mud->cb_connect_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_connect_ref);
|
||||
mud->cb_connect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}else if( sl == 7 && c_strcmp(method, "offline") == 0){
|
||||
if(mud->cb_disconnect_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_disconnect_ref);
|
||||
mud->cb_disconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}else if( sl == 7 && c_strcmp(method, "message") == 0){
|
||||
if(mud->cb_message_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_message_ref);
|
||||
mud->cb_message_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}else{
|
||||
|
@ -1298,7 +1276,6 @@ static int mqtt_socket_unsubscribe( lua_State* L ) {
|
|||
|
||||
if( lua_type( L, stack ) == LUA_TFUNCTION || lua_type( L, stack ) == LUA_TLIGHTFUNCTION ) { // TODO: this will overwrite the previous one.
|
||||
lua_pushvalue( L, stack ); // copy argument (func) to the top of stack
|
||||
if( mud->cb_unsuback_ref != LUA_NOREF )
|
||||
luaL_unref( L, LUA_REGISTRYINDEX, mud->cb_unsuback_ref );
|
||||
mud->cb_unsuback_ref = luaL_ref( L, LUA_REGISTRYINDEX );
|
||||
}
|
||||
|
@ -1414,7 +1391,6 @@ static int mqtt_socket_subscribe( lua_State* L ) {
|
|||
|
||||
if( lua_type( L, stack ) == LUA_TFUNCTION || lua_type( L, stack ) == LUA_TLIGHTFUNCTION ) { // TODO: this will overwrite the previous one.
|
||||
lua_pushvalue( L, stack ); // copy argument (func) to the top of stack
|
||||
if( mud->cb_suback_ref != LUA_NOREF )
|
||||
luaL_unref( L, LUA_REGISTRYINDEX, mud->cb_suback_ref );
|
||||
mud->cb_suback_ref = luaL_ref( L, LUA_REGISTRYINDEX );
|
||||
}
|
||||
|
@ -1490,7 +1466,6 @@ static int mqtt_socket_publish( lua_State* L )
|
|||
|
||||
if (lua_type(L, stack) == LUA_TFUNCTION || lua_type(L, stack) == LUA_TLIGHTFUNCTION){
|
||||
lua_pushvalue(L, stack); // copy argument (func) to the top of stack
|
||||
if(mud->cb_puback_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_puback_ref);
|
||||
mud->cb_puback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue