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; }
void childLoop() { char msg[80]; struct sockaddr_in fsin; int len=0; int cs=0; /* Loop forever waiting for connections */ for(;;) { len=sizeof(fsin); /* Look for connections. */ cs=accept(lsocket, (struct sockaddr *) & fsin, &len); /* Immediately close them */ if(cs>=0) { close(cs); } sprintf(msg, "Connection attempt from %s", inet_ntoa(fsin.sin_addr)); xloop(msg); } }
/** * This function is called right after the configuration was parsed. * It simply: * - creates the main listening sockets (control and proxy) * - initialize the signal mask * - initialize all the VMs * - fill the plugin list with the valid plugins located in the autoload path * - then call the main thread loop * - once finished, it also cleans the structures * * @return 0 if everything went well, -1 otherwise with an error message */ int proxenet_start() { sock_t control_socket, listening_socket; struct sigaction saction; /* create control socket */ control_socket = proxenet_bind_control_socket(); if (control_socket < 0) { xlog(LOG_CRITICAL, "Cannot create control socket: %s\n", strerror(errno)); return -1; } if(cfg->verbose) xlog(LOG_INFO, "Control socket: %d\n", control_socket); /* create listening socket */ listening_socket = proxenet_bind_socket(cfg->iface, cfg->port); if (listening_socket < 0) { xlog(LOG_CRITICAL, "Cannot create bind socket: %s\n", strerror(errno)); return -1; } if(cfg->verbose) xlog(LOG_INFO, "Bind socket: %d\n", listening_socket); /* 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; /* this call *MUST* succeed or die */ proxenet_initialize_plugins(); /* setting request counter */ request_id = 0; /* we "artificially" allocate an ID 0 so that all new requests will be > 0 */ /* for the child threads, a request id of 0 means not allocated */ get_new_request_id(); init_global_stats(); /* prepare threads and start looping */ xloop(listening_socket, control_socket); end_global_stats(); if (cfg->verbose) print_global_stats(); /* clean context */ proxenet_destroy_plugins_vm(); proxenet_free_all_plugins(); proxenet_close_socket(listening_socket, NULL); proxenet_close_socket(control_socket, NULL); unlink(CFG_CONTROL_SOCK_PATH); return 0; }