binmodules/luasocket/src/tcp.c
/*-------------------------------------------------------------------------*\
* Turns a master tcp object into a client object.
\*-------------------------------------------------------------------------*/
\
Turns a master tcp object into a client object.
\ Turns a master tcp object into a client object .
static int meth_connect(lua_State *L) {
    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, "tcp{any}", 1);
    const char *address =  luaL_checkstring(L, 2);
    const char *port = luaL_checkstring(L, 3);
    struct addrinfo connecthints;
    const char *err;
    memset(&connecthints, 0, sizeof(connecthints));
    connecthints.ai_socktype = SOCK_STREAM;
    connecthints.ai_family = tcp->family;
    timeout_markstart(&tcp->tm);
    err = inet_tryconnect(&tcp->sock, &tcp->family, address, port,
        &tcp->tm, &connecthints);
    auxiliar_setclass(L, "tcp{client}", 1);
    if (err) {
        lua_pushnil(L);
        lua_pushstring(L, err);
        return 2;
    }
    lua_pushnumber(L, 1);
    return 1;
}
static int meth_connect ( lua_State * L ) { p_tcp tcp = ( p_tcp ) auxiliar_checkgroup ( L , " " , 1 ) ; const char * address = luaL_checkstring ( L , 2 ) ; const char * port = luaL_checkstring ( L , 3 ) ; struct addrinfo connecthints ; const char * err ; memset ( & connecthints , 0 , sizeof ( connecthints ) ) ; connecthints . ai_socktype = SOCK_STREAM ; connecthints . ai_family = tcp -> family ; timeout_markstart ( & tcp -> tm ) ; err = inet_tryconnect ( & tcp -> sock , & tcp -> family , address , port , & tcp -> tm , & connecthints ) ; auxiliar_setclass ( L , " " , 1 ) ; if ( err ) { lua_pushnil ( L ) ; lua_pushstring ( L , err ) ; return 2 ; } lua_pushnumber ( L , 1 ) ; return 1 ; }
\
Turns a master tcp object into a client object.
\ Turns a master tcp object into a client object .
/* make sure we try to connect only to the same family */ /* have to set the class even if it failed due to non-blocking connects */