Beispiel #1
0
bool node_lua_t::context_send(uint32_t handle, message_t& msg)
{
	context_t *ctx = m_ctx_mgr->grab_context(handle);
	if (ctx) {
		bool ret = context_send(ctx, msg);
		ctx->release();
		return ret;
	}
	return false;
}
Beispiel #2
0
int32_t context_lua_t::context_query(lua_State *L)
{
	uint32_t handle = luaL_checkunsigned(L, 1);
	int32_t top = lua_gettop(L);
	uint64_t timeout = 0;
	int32_t callback = 0;
	if (top >= 3) { //nonblocking
		if (lua_isfunction(L, 3)) {
			callback = 3;
		} else {
			timeout = 1000 * luaL_checknumber(L, 3);
			if (top >= 4) {
				luaL_checktype(L, 4, LUA_TFUNCTION);
				callback = 4;
			}
		}
	}
	if (callback > 0) {
		lua_settop(L, callback);
		lua_pushvalue(L, 2);
		lua_insert(L, 1);
		int32_t session = context_lua_t::lua_ref_callback(L, callback - 1, LUA_REFNIL, common_callback_adjust);
		int32_t ret = context_send(L, 1, handle, session, CONTEXT_QUERY);
		if (ret == UV_OK) {
			if (timeout > 0) {
				context_lua_t::lua_ref_timer(L, session, timeout, 0, false);
			}
			lua_pushboolean(L, 1);
			lua_pushinteger(L, session);
			return 2;
		}
		context_lua_t::lua_free_ref_session(L, session);
		if (ret == NL_ETRANSTYPE) {
			luaL_argerror(L, 2, common_strerror(NL_ETRANSTYPE));
			return 0;
		}
		lua_pushboolean(L, 0);
		lua_pushinteger(L, NL_ENOCONTEXT);
		return 2;
	}
	context_lua_t* lctx = context_lua_t::lua_get_context(L);
	message_t& message = lctx->get_yielding_message();
	int ret = context_check_message(L, 2, CONTEXT_QUERY, message);
	if (ret != UV_OK) {
		luaL_argerror(L, 2, common_strerror(ret));
		return 0;
	}
	return lctx->lua_yield_send(L, handle, context_query_yield_finalize, NULL, context_lua_t::context_query_yield_continue, timeout);
}
Beispiel #3
0
int32_t context_lua_t::context_send(lua_State *L)
{
	uint32_t handle = luaL_checkunsigned(L, 1);
	int32_t ret = context_send(L, 2, handle, LUA_REFNIL, CONTEXT_QUERY);
	if (ret == UV_OK) {
		lua_pushboolean(L, 1);
		return 1;
	}
	if (ret == NL_ETRANSTYPE) {
		luaL_argerror(L, 2, common_strerror(NL_ETRANSTYPE));
		return 0;
	}
	lua_pushboolean(L, 0);
	lua_pushinteger(L, NL_ENOCONTEXT);
	return 2;
}
Beispiel #4
0
int32_t context_lua_t::context_reply(lua_State *L)
{
	uint32_t handle = luaL_checkunsigned(L, 1);
	int32_t session = luaL_checkinteger(L, 2);
	int32_t ret = context_send(L, 3, handle, session, CONTEXT_REPLY);
	if (ret == UV_OK) {
		lua_pushboolean(L, 1);
		return 1;
	}
	if (ret == NL_ETRANSTYPE) {
		context_t* ctx = lua_get_context(L);
		singleton_ref(node_lua_t).context_send(handle, ctx->get_handle(), session, CONTEXT_REPLY, NL_ETRANSTYPE);
		luaL_argerror(L, 3, common_strerror(NL_ETRANSTYPE));
		return 0;
	}
	lua_pushboolean(L, 0);
	lua_pushinteger(L, NL_ENOCONTEXT);
	return 2;
}