ldcsaa/HP-Socket

C语言问题

Closed this issue · 6 comments

callback函数如何知道自己的数据?

HP_Set_FN_Server_xxxx的函数是否应该添加一个userdata
或者类似 HP_Server_SetConnectionExtra 弄个setuserdata
HP_Server_SetConnectionExtra只能对连接设置

回调函数第一个参数,pSender

我是说自定义数据,类似 HP_Server_SetConnectionExtra

pSender就是组件的this指针了,有了this不就能看对象的信息了么?

C语言啊,pSender指向HP_Object,就一指针有什么用啊,自己写索引吗

static void on_recv(hio_t *io, void *buf, int len)
{
    connection_t *conn = (connection_t *)hevent_userdata(io);
    if (!conn)
        return;
    lua_State *L = conn->svr->L;
    if (conn->svr->lon_recv)
    {
        lua_rawgeti(L, LUA_REGISTRYINDEX, conn->svr->lon_recv);
        lua_pushinteger(L, hio_id(io));
        lua_pushlstring(L, (char *)buf, len);
        lua_call(L, 2, 0);
    }
}

这是一个简单的userdata