int run(void) { int ret = 0; GMainLoop* main_loop; GInetAddr* addr; GServer* server; /* Create the main loop */ main_loop = g_main_new(FALSE); /* Create the interface */ addr = gnet_inetaddr_new_any (); gnet_inetaddr_set_port (addr, OPT_VALUE_LISTEN); /* Create the server */ server = gnet_server_new (addr, TRUE, ob_server_func, "hallo"); if (!server) { fprintf (stderr, "Error: Could not start server\n"); return(0); } ob_server = server; signal (SIGTERM, ob_sig_term); /* Start the main loop */ g_main_run(main_loop); return(1); }
/* * Load the server's placed "UP" in the architecture, the master/s server/s * */ void sim_xml_config_set_config_rserver (SimXmlConfig *xmlconfig, SimConfig *config, xmlNodePtr node) { SimConfigRServer *rserver; gchar *value; g_return_if_fail (xmlconfig); g_return_if_fail (SIM_IS_XML_CONFIG (xmlconfig)); g_return_if_fail (config); g_return_if_fail (SIM_IS_CONFIG (config)); g_return_if_fail (node); if (strcmp ((gchar *) node->name, OBJECT_RSERVER)) { g_message ("Invalid config rserver node %s", node->name); return; } rserver = sim_config_rserver_new (); if ((value = (gchar *) xmlGetProp (node, (xmlChar *) PROPERTY_NAME))) { rserver->name = g_strdup (value); xmlFree(value); } if ((value = (gchar *) xmlGetProp (node, (xmlChar *) PROPERTY_IP))) { if (value) { rserver->ia = gnet_inetaddr_new_nonblock (value, 0); if (rserver->ia) { rserver->ip = g_strdup (value); xmlFree(value); } else { g_message ("Error: May be that you introduced a bad remote server IP in the server's config.xml?"); sim_config_rserver_free(rserver); xmlFree(value); return; } } else { g_message ("Error: May be that you didn't introduced a remote server IP in the server's config.xml?"); sim_config_rserver_free(rserver); return; } } if ((value = (gchar *) xmlGetProp (node, (xmlChar *) PROPERTY_PORT))) { if (sim_string_is_number (value, 0)) { rserver->port = strtol (value, (char **) NULL, 10); xmlFree(value); } else { g_message ("Error: May be that you introduced a bad remote IP port in the server's config.xml?"); sim_config_rserver_free(rserver); xmlFree(value); return; } } if ((value = (gchar *) xmlGetProp (node, (xmlChar *) PROPERTY_HA_ROLE))) { if (!g_ascii_strcasecmp (value, "active")) { rserver->is_HA_server = TRUE; rserver->HA_role = HA_ROLE_ACTIVE; } else if (!g_ascii_strcasecmp (value, "passive")) { rserver->is_HA_server = TRUE; rserver->HA_role = HA_ROLE_PASSIVE; } else { rserver->is_HA_server = FALSE; rserver->HA_role = HA_ROLE_NONE; } xmlFree(value); } if ((value = (gchar *) xmlGetProp (node, (xmlChar *) PROPERTY_PRIMARY))) { if (!g_ascii_strcasecmp (value, "true")) { rserver->primary = TRUE; } else if (!g_ascii_strcasecmp (value, "false")) { rserver->primary = FALSE; } else { g_message ("Error: May be that you introduced a bad primary in the server's config.xml?: please write TRUE or FALSE"); xmlFree(value); sim_config_rserver_free(rserver); return; } xmlFree(value); } if (!rserver->port) { rserver->port = 40001; } gnet_inetaddr_set_port (rserver->ia, rserver->port); config->rservers = g_list_append (config->rservers, rserver); }