예제 #1
0
파일: lua-ext.c 프로젝트: matrixj/alilua
int lua_die ( lua_State *L )
{
    if ( !lua_isuserdata ( L, 1 ) ) {
        luaL_error ( L, "miss epd!" );
        return 0;
    }

    epdata_t *epd = lua_touserdata ( L, 1 );
    network_be_end ( epd );
    lua_pushnil ( L );
    lua_error ( L ); /// stop lua script
    return 0;
}
예제 #2
0
파일: lua-ext.c 프로젝트: matrixj/alilua
int lua_check_timeout ( lua_State *L )
{
    if ( !lua_isuserdata ( L, 1 ) ) {
        luaL_error ( L, "miss epd!" );
        return 0;
    }

    epdata_t *epd = lua_touserdata ( L, 1 );

    if ( epd->process_timeout == 1 ) {
        epd->keepalive = 0;
        network_be_end ( epd );
        lua_pushstring ( L, "Process Time Out!" );
        lua_error ( L ); /// stop lua script
    }

    return 0;
}
예제 #3
0
파일: lua-ext.c 프로젝트: cofyc/alilua
int lua_end(lua_State *L)
{
    epdata_t *epd = get_epd(L);

    if(!epd) {
        return 0;
    }

    if(epd->status != STEP_PROCESS) {
        return 0;
    }

    if(epd->websocket || epd->status == STEP_SEND) {
        return 0;
    }

    network_be_end(epd);
    return 0;
}
예제 #4
0
파일: lua-ext.c 프로젝트: cofyc/alilua
int lua_sendfile(lua_State *L)
{
    epdata_t *epd = get_epd(L);

    if(!epd) {
        lua_pushnil(L);
        lua_pushstring(L, "miss epd!");
        return 2;
    }

    if(epd->header_sended != 0) {
        lua_pushnil(L);
        lua_pushstring(L, "respone header has been sended");
        return 2;
    }

    if(!lua_isstring(L, 1)) {
        lua_pushnil(L);
        lua_pushstring(L, "Need a file path!");
        return 2;
    }

    size_t len = 0;
    const char *fname = lua_tolstring(L, 1, &len);
    //char *full_fname = malloc(epd->vhost_root_len + len);
    char *full_fname = (char *)&temp_buf;
    memcpy(full_fname, epd->vhost_root, epd->vhost_root_len);
    memcpy(full_fname + epd->vhost_root_len , fname, len);
    full_fname[epd->vhost_root_len + len] = '\0';

    network_sendfile(epd, full_fname);

    //free(full_fname);

    lua_pushnil(L);
    lua_error(L); /// stop lua script

    network_be_end(epd);

    return 0;
}