示例#1
0
void redis_pool_init(char *host, int port)
{
	char key[64] = {};
	if (!g_hmap){
		g_hmap = hashmap_open();
		assert(g_hmap != NULL);
	}

	struct cnt_pool *pool = calloc(1, sizeof(struct cnt_pool));
	cnt_init ( pool, 20000, new_connect, del_connect );
	sprintf(key, "%s:%d", host, port);
	x_printf(D, "pool addr is %p\n", pool);
        hashmap_set(g_hmap, key, strlen(key), &pool, sizeof(uintptr_t *));

	uintptr_t *cite = NULL;
	cnt_pull ( pool, &cite, host, port );
	printf("|-------%s redis pool init------->%s\n", key, (cite)?" OK!":" FAIL!");
	assert (cite);
	cnt_push ( pool, &cite );
	x_printf(D, "cite is %p\n", cite);
	return;
}
示例#2
0
文件: main.c 项目: elambert/honeycomb
/* 
 * The main method of the Cluster Membership Monitor 
 */
int
main( int argc,
      char *argv[] )
{
    int c;
    cmm_nodeid_t node_id = CMM_INVALID_NODE_ID;
    char *filename = NULL;
    cmm_error_t err;
    cm_trace_level_t trace_level = CM_TRACE_LEVEL_NOTICE;
    fifo_t *lobby_to_sender, *stack_to_sender;
    int pipe_stack[2];
    struct sigaction action;

    /* Read and verify the input arguments */

    while ( (c=getopt(argc, argv, "n:f:d")) != EOF ) {
        switch (c) {
        case 'n' :
            node_id = atoi( argv[optind-1] );
            break;
            
        case 'f' :
            filename = strdup(optarg);
            if (!filename) {
                cm_trace(CM_TRACE_LEVEL_ERROR, 
                         "strdup failed" );
                exit(1);
            }
            break;
            
        case 'd' :
            trace_level = CM_TRACE_LEVEL_DEBUG;
            break;
        }
    }

    if ( node_id == CMM_INVALID_NODE_ID ) {
        usage( argv[0],
               "The node id paramater has to be specified" );
    }

    if ( filename == NULL ) {
        usage( argv[0],
               "The configuration file parameter has to be specified" );
    }

    daemonize();
    
    cm_openlog("CMM", trace_level);

    /* Block the SIGPIPE signals */
    
    action.sa_handler = SIG_IGN;
    if (sigaction(SIGPIPE, &action, NULL)) {
        cm_trace(CM_TRACE_LEVEL_ERROR,
                 "sigaction failed");
        cm_closelog();
        return(1);
    }

    cm_trace(CM_TRACE_LEVEL_NOTICE,
             "The local node id is %d",
             node_id );

    cm_trace(CM_TRACE_LEVEL_DEBUG,
             "The configuration file is %s",
             filename );


    err = cnt_init( filename, node_id );
    if (err != CMM_OK) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "cnt_init failed [%d]",
                 err );
        return(1);
    }

    cnt_print();

    if ( pipe(pipe_stack) ) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "pipe failed" );
        return(1);
    }
    
    cm_trace(CM_TRACE_LEVEL_DEBUG,
             "stack pipe has been created (%d %d)",
             pipe_stack[0], pipe_stack[1] );
    
    stack_to_sender = fifo_init(NULL);
    if (!stack_to_sender) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "fifo_init failed" );
        return(1);
    }

    lobby_to_sender = fifo_init(stack_to_sender);
    if (!lobby_to_sender) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "fifo_init failed" );
        return(1);
    }

    /* start the lobby server thread to listen to incoming messages from 
     * the predecessor node 
     */

    err = lobby_start( RING_PORT,
                       pipe_stack[1],
                       lobby_to_sender );
    if (err != CMM_OK) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "lobby_start failed [%d]",
                 err );
        return(1);
    }

    /* start the sender server thread to establish connection with the 
     * successor node and send messages to it from the lobby_to_sender and 
     * the stack_to_sender fifos
     */
    err = sender_start( lobby_to_sender,
                        stack_to_sender );
    if (err != CMM_OK) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "sender_start failed [%d]",
                 err );
        return(1);
    }

    /* Start the api server */

    err = api_init();
    if (err != CMM_OK) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "api_init failed [%d]",
                 err );
        return(1);
    }
/*     err = heartbeat_start(); */
/*     if (err != CMM_OK) { */
/*         cm_trace(CM_TRACE_LEVEL_ERROR,  */
/*                  "heartbeat init failed [%d]", err); */
/*         return (1); */
/*     } */
    stack_start( pipe_stack[0], stack_to_sender );

    cm_trace(CM_TRACE_LEVEL_ERROR, 
             "The stack exited !");
    
    cm_closelog();

    return(0);
}