Пример #1
0
hoxResult
hoxDbClient::initialize( const char* szHost,
                         int         nPort )
{
    const char* FNAME = "hoxDbClient::initialize";
    hoxResult result = hoxRC_UNKNOWN;

    hoxLog(LOG_INFO, "%s: ENTER. [%s:%d]", FNAME, szHost, nPort);

    if ( s_bInitialized )
    {
        hoxLog(LOG_DEBUG, "%s: The module has already initialized.", FNAME);
        return hoxRC_OK;
    }

    s_mutex = st_mutex_new();  // ... to provide exclusive assess

    /* Open a "shared" client socket. */
    s_nfd = _open_client_socket( szHost, nPort );
    if ( s_nfd == NULL )
    {
        hoxLog(LOG_ERROR, "%s: Failed to open a client socket.", FNAME);
        return hoxRC_OK;
    }

    s_bInitialized = true;

    /* Send an "HELLO" request to make sure that the DB Agent is OK. */
    result = send_HELLO();
    if ( result != hoxRC_OK )
    {
        hoxLog(LOG_ERROR, "%s: Failed to send HELLO request.", FNAME);
        return hoxRC_ERR;
    }

    /* Start a "write" thread to help avoiding blocking
     * handlers of client requests.
     */

    s_writeCond = st_cond_new();

    s_writeThread = st_thread_create( _handle_db_write,
                                      ( void * ) NULL,
                                      1 /* joinable */,
                                      0 /* stack-size */ );
    if ( s_writeThread == NULL )
    {
        hoxLog(LOG_ERROR, "%s: Failed to create write DB thread.", FNAME);
        return hoxRC_ERR;
    }

    hoxLog(LOG_DEBUG, "%s: END. (OK)", FNAME);
    return hoxRC_OK;
}
Пример #2
0
/*---------------------------------------------------------------------
 * Method: pwospf_run_thread
 *
 * Main thread of pwospf subsystem.
 *
 *---------------------------------------------------------------------*/
static
void* pwospf_run_thread(void* arg)
{
    struct sr_instance* sr = (struct sr_instance*)arg;
    while(1)
    {
        /* -- PWOSPF subsystem functionality should start  here! -- */
        int i;
        for(i = 0; i < OSPF_DEFAULT_LSUINT; i += OSPF_DEFAULT_HELLOINT)
        {
        	send_HELLO(sr);
        	sleep(OSPF_DEFAULT_HELLOINT);
        }
        /*Send LSU updates*/
        
        check_top_invalid(sr); /*Check for expired topo entries*/
    	send_lsu(sr);
    }
} /* -- run_ospf_thread -- */