CRoute_manager::CRoute_manager() { readconf("./conf.json"); if( (maintain_servfd = create_bind_socket("8080")) == -1 ) exit(-1); if(listen(maintain_servfd, 10) == -1) exit(-1); if( (info_fd = create_bind_socket("9090")) == -1 ) exit(-1); if(make_socket_non_blocking(info_fd) == -1) exit(1); if(listen(info_fd, SOMAXCONN) == -1) exit(-1); if( pthread_create(&mt_thread_id,NULL,maintain_thread,(void*)this) != 0 ) exit(-1); if( pthread_create(&info_thread_id,NULL,cellinfo_thread,(void*)this) != 0 ) exit(-1); // if( pthread_create(&thread_id,NULL,request_cellinfo_thread,(void*)this) != 0 ) // exit(-1); }
int proxenet_start() { sock_t control_socket, listening_socket; struct sigaction saction; control_socket = listening_socket = -1; /* create control socket */ control_socket = create_control_socket(); if (control_socket < 0) { xlog(LOG_CRITICAL, "Cannot create control socket: %s\n", strerror(errno)); return -1; } #ifdef DEBUG xlog(LOG_INFO, "Control socket: %d\n", control_socket); #endif /* create listening socket */ listening_socket = create_bind_socket(cfg->iface, cfg->port); if (listening_socket < 0) { xlog(LOG_CRITICAL, "Cannot create bind socket: %s\n", strerror(errno)); return -1; } #ifdef DEBUG xlog(LOG_INFO, "Bind socket: %d\n", listening_socket); #endif /* init everything */ initialize_sigmask(&saction); plugins_list = NULL; proxy_state = INACTIVE; active_threads_bitmask = 0; /* set up plugins */ if( proxenet_initialize_plugins_list() < 0 ) return -1; proxenet_initialize_plugins(); // call *MUST* succeed or abort() /* setting request counter */ request_id = 0; get_new_request_id(); /* prepare threads and start looping */ xloop(listening_socket, control_socket); /* clean context */ proxenet_remove_all_plugins(); close_socket(listening_socket); close_socket(control_socket); unlink(CONTROL_SOCK_PATH); return 0; }