Esempio n. 1
0
File: glb_lib.c Progetto: Zlo/glb
static void glb_init()
{
//    fprintf (stderr, "GLB_OPTIONS='%s'\n", getenv ("GLB_OPTIONS"));
//    fprintf (stderr, "GLB_BIND='%s'\n",    getenv ("GLB_BIND"));
//    fprintf (stderr, "GLB_TARGETS='%s'\n", getenv ("GLB_TARGETS"));

    glb_cnf = glb_env_parse();

    if (glb_cnf)
    {
        if (glb_cnf->verbose) glb_cnf_print(stdout, glb_cnf);

        glb_log_init (GLB_LOG_STDERR, glb_cnf->verbose);

        glb_router = glb_router_create(glb_cnf);

        if (glb_router)
        {
            glb_wdog_t* wdog = NULL;

            if (glb_cnf->watchdog)
            {
                wdog = glb_wdog_create(glb_cnf, glb_router, NULL);
            }

            if (glb_cnf->ctrl_set)
            {
                uint16_t const default_port =
                    glb_sockaddr_get_port(&glb_cnf->inc_addr);

                int const sock = glb_socket_create(&glb_cnf->ctrl_addr, 0);

                if (sock > 0)
                    glb_ctrl_create(glb_cnf, glb_router, NULL, wdog,
                                    default_port, 0, sock);
            }
        }
    }

    if (!glb_router)
    {
        fputs (LIBGLB_PREFIX "Failed to initialize.\n", stderr);
        fflush (stderr);
    }

    glb_real_connect = dlsym(RTLD_NEXT, "__connect");
}
Esempio n. 2
0
// returns socket number or negative error code
int
glb_router_connect (glb_router_t* router, glb_sockaddr_t* dst_addr)
{
    int sock, ret;

    // prepare a socket
    sock = glb_socket_create (&router->sock_out);
    if (sock < 0) {
        glb_log_error ("glb_socket_create() failed");
        return sock;
    }

    // attmept to connect until we run out of destinations
    ret = router_connect_dst (router, sock, dst_addr);

    // avoid socket leak
    if (ret < 0) {
        glb_log_error ("router_connect_dst() failed");
        close (sock);
	sock = ret;
    }

    return sock;
}