void hub_shutdown_service(struct hub_info* hub) { LOG_DEBUG("hub_shutdown_service()"); if (net_backend_get_timeout_queue()) { timeout_queue_remove(net_backend_get_timeout_queue(), hub->stats.timeout); hub_free(hub->stats.timeout); } #ifdef SSL_SUPPORT unload_ssl_certificates(hub); #endif event_queue_shutdown(hub->queue); net_con_close(hub->server); server_alt_port_stop(hub); uman_shutdown(hub->users); list_clear(hub->muxes, &hub_mux_destroy); list_destroy(hub->muxes); hub->status = hub_status_stopped; hub_free(hub->sendbuf); hub_free(hub->recvbuf); list_clear(hub->logout_info, &hub_free); list_destroy(hub->logout_info); command_shutdown(hub->commands); hub_free(hub); hub = 0; g_hub = 0; }
void hub_disconnect_user(struct hub_info* hub, struct hub_user* user, int reason) { struct event_data post; int need_notify = 0; /* is user already being disconnected ? */ if (user_is_disconnecting(user)) { return; } /* stop reading from user */ net_shutdown_r(net_con_get_sd(user->connection)); net_con_close(user->connection); user->connection = 0; LOG_TRACE("hub_disconnect_user(), user=%p, reason=%d, state=%d", user, reason, user->state); need_notify = user_is_logged_in(user) && hub->status == hub_status_running; user->quit_reason = reason; user_set_state(user, state_cleanup); if (need_notify) { memset(&post, 0, sizeof(post)); post.id = UHUB_EVENT_USER_QUIT; post.ptr = user; event_queue_post(hub->queue, &post); } else { hub_schedule_destroy_user(hub, user); } }
static void ADC_client_on_disconnected(struct ADC_client* client) { ADC_TRACE; net_con_close(client->con); client->con = 0; ADC_client_set_state(client, ps_none); }
static void net_connect_job_free(struct net_connect_job* job) { if (job->con) net_con_close(job->con); job->handle = NULL; job->next = NULL; hub_free(job); }
static void server_alt_port_clear(void* ptr) { struct net_connection* con = (struct net_connection*) ptr; if (con) { net_con_close(con); hub_free(con); } }
void ADC_client_disconnect(struct ADC_client* client) { ADC_TRACE; if (client->con && net_con_get_sd(client->con) != -1) { net_con_close(client->con); client->con = 0; } }
void probe_destroy(struct hub_probe* probe) { LOG_TRACE("probe_destroy(): %p (connection=%p)", probe, probe->connection); if (probe->connection) { net_con_close(probe->connection); probe->connection = 0; } hub_free(probe); }
void user_destroy(struct hub_user* user) { LOG_TRACE("user_destroy(), user=%p", user); ioq_recv_destroy(user->recv_queue); ioq_send_destroy(user->send_queue); if (user->connection) { LOG_TRACE("user_destory() -> net_con_close(%p)", user->connection); net_con_close(user->connection); } adc_msg_free(user->info); user_clear_feature_cast_support(user); hub_free(user); }
void hub_shutdown_service(struct hub_info* hub) { LOG_DEBUG("hub_shutdown_service()"); #ifdef SSL_SUPPORT unload_ssl_certificates(hub); #endif event_queue_shutdown(hub->queue); net_con_close(hub->server); hub_free(hub->server); server_alt_port_stop(hub); uman_shutdown(hub); hub->status = hub_status_stopped; hub_free(hub->sendbuf); hub_free(hub->recvbuf); hub_chat_history_clear(hub); list_destroy(hub->chat_history); list_clear(hub->logout_info, &hub_free); list_destroy(hub->logout_info); hub_free(hub); hub = 0; g_hub = 0; }
struct hub_info* hub_start_service(struct hub_config* config) { struct hub_info* hub = 0; int ipv6_supported; hub = hub_malloc_zero(sizeof(struct hub_info)); if (!hub) { LOG_FATAL("Unable to allocate memory for hub"); return 0; } hub->tm_started = time(0); ipv6_supported = net_is_ipv6_supported(); if (ipv6_supported) LOG_DEBUG("IPv6 supported."); else LOG_DEBUG("IPv6 not supported."); hub->server = start_listening_socket(config->server_bind_addr, config->server_port, config->server_listen_backlog, hub); if (!hub->server) { hub_free(hub); LOG_FATAL("Unable to start hub service"); return 0; } LOG_INFO("Starting " PRODUCT "/" VERSION ", listening on %s:%d...", net_get_local_address(hub->server->sd), config->server_port); #ifdef SSL_SUPPORT if (!load_ssl_certificates(hub, config)) { hub_free(hub); return 0; } #endif hub->config = config; hub->users = NULL; hub->muxes = list_create(); hub->users = uman_init(); if (!hub->users) { net_con_close(hub->server); hub_free(hub); return 0; } if (event_queue_initialize(&hub->queue, hub_event_dispatcher, (void*) hub) == -1) { net_con_close(hub->server); uman_shutdown(hub->users); hub_free(hub); return 0; } hub->recvbuf = hub_malloc(MAX_RECV_BUF); hub->sendbuf = hub_malloc(MAX_SEND_BUF); if (!hub->recvbuf || !hub->sendbuf) { net_con_close(hub->server); hub_free(hub->recvbuf); hub_free(hub->sendbuf); uman_shutdown(hub->users); hub_free(hub); return 0; } hub->logout_info = (struct linked_list*) list_create(); server_alt_port_start(hub, config); hub->status = hub_status_running; g_hub = hub; if (net_backend_get_timeout_queue()) { hub->stats.timeout = hub_malloc_zero(sizeof(struct timeout_evt)); timeout_evt_initialize(hub->stats.timeout, hub_timer_statistics, hub); timeout_queue_insert(net_backend_get_timeout_queue(), hub->stats.timeout, TIMEOUT_STATS); } // Start the hub command sub-system hub->commands = command_initialize(hub); return hub; }