Esempio n. 1
0
/*-------------------------------------------------------------------------*\
* 
\*-------------------------------------------------------------------------*/
int sock_listen(p_sock ps, int backlog) {
    int err = IO_DONE; 
    sock_setblocking(ps);
    if (listen(*ps, backlog)) err = errno; 
    sock_setnonblocking(ps);
    return err;
}
Esempio n. 2
0
/*-------------------------------------------------------------------------*\
* Binds or returns error message
\*-------------------------------------------------------------------------*/
int sock_bind(p_sock ps, SA *addr, socklen_t len) {
    int err = IO_DONE;
    sock_setblocking(ps);
    if (bind(*ps, addr, len) < 0) err = errno; 
    sock_setnonblocking(ps);
    return err;
}
Esempio n. 3
0
/*-------------------------------------------------------------------------*\
* Creates a master udp object 
\*-------------------------------------------------------------------------*/
static int global_create(lua_State *L) {
    t_sock sock;
    const char *err = inet_trycreate(&sock, SOCK_DGRAM);
    /* try to allocate a system socket */
    if (!err) { 
        /* allocate tcp object */
        p_udp udp = (p_udp) lua_newuserdata(L, sizeof(t_udp));
        aux_setclass(L, "udp{unconnected}", -1);
        /* initialize remaining structure fields */
        sock_setnonblocking(&sock);
        udp->sock = sock;
        tm_init(&udp->tm, -1, -1);
        return 1;
    } else {
        lua_pushnil(L);
        lua_pushstring(L, err);
        return 2;
    }
}
Esempio n. 4
0
/*-------------------------------------------------------------------------*\
* 
\*-------------------------------------------------------------------------*/
void sock_shutdown(p_sock ps, int how) {
    sock_setblocking(ps);
    shutdown(*ps, how);
    sock_setnonblocking(ps);
}