示例#1
0
文件: lua-kcp.c 项目: korialuo/skynet
static int
lupdate(lua_State *l) {
    struct kcpctx *ctx = (struct kcpctx *)luaL_checkudata(l, 1, LKCP_MT);
    if (!ctx)
        return luaL_argerror(l, 1, "parameter self invalid.");
    assert(ctx->kcp);

    uint32_t tick = (uint32_t)luaL_checkinteger(l, 2);
    if (tick >= ctx->timeout) {
        ikcp_update(ctx->kcp, tick);
        ctx->timeout = ikcp_check(ctx->kcp, tick);
    }

    return 0;
}
示例#2
0
文件: etp.c 项目: canmor-lam/libsg
/* for libuv */
static void on_uv_timer_cb(uv_timer_t * handle)
{
    sg_etp_session_t * session = handle->data;
    IUINT32 now = 0;

    /*LOG_D("update %d", client->conv);*/

    /* update ikcp */
    now = (IUINT32)uv_now(session->loop);
    sg_etp_update_speed((sg_etp_t *)session, now);
    if (now >= session->kcp_update_time)
    {
        ikcp_update(session->kcp, now);
        session->kcp_update_time = ikcp_check(session->kcp, now);

        LOG_D("update %lu @ %lu, timeout: %lu", session->conv, session->kcp_update_time, session->recv_data_time);

        /* check received data and add to work queue */
        //recv_data_check(session);
        if (ikcp_peeksize(session->kcp) > 0)
        {
            uv_idle_start(&(session->idle), on_uv_idle_cb);
        }
    }

    /* check if session is timeout */
    if (session->recv_data_time < now)
    {
        session->to_close = true; /* mark to close this session. */
        ikcp_flush(session->kcp);
        LOG_I("session %lu timeout, will be closed", session->conv);
    }

    /* check if should close this session */
    if (session->to_close)
    {
        sg_etp_session_close(session);
    }
}