int proxy::run() { try { this->instance_.listen(a_.bind_address, a_.port); LOG(INFO) << "start listening at port " << a_.port; start_time_= jubatus::util::system::time::get_clock_time(); this->instance_.start(a_.threadnum); // RPC server started, then register group membership register_proxy(*zk_, a_.type, a_.eth, a_.port); LOG(INFO) << "registered group membership"; LOG(INFO) << common::get_program_name() << " RPC server startup"; common::set_action_on_term( jubatus::util::lang::bind(&stop_rpc_server, jubatus::util::lang::ref(this->instance_))); this->instance_.join(); return 0; } catch (const jubatus::core::common::exception::jubatus_exception& e) { LOG(FATAL) << "exception when starting RPC server: " << e.diagnostic_information(true); } catch (const mp::system_error& e) { if (e.code == EADDRINUSE) { LOG(FATAL) << "server failed to start: " << e.what() << " (any process using port " << a_.port << "?)"; } else { LOG(FATAL) << "server failed to start: " << e.what(); } } catch (const std::exception& e) { LOG(FATAL) << "error when starting RPC server: " << e.what(); } return -1; }
static void process_register(pep_proxy_t *proxy, register_msg_t *reg) { int error; const char *errmsg; if (register_proxy(proxy, reg->name, reg->tables, reg->ntable, reg->watches, reg->nwatch, &error, &errmsg)) { msg_send_ack(proxy, reg->seq); proxy->notify_all = TRUE; schedule_notification(proxy->pdp); } else msg_send_nak(proxy, reg->seq, error, errmsg); }
static DBusMessage *create_proxy(DBusConnection *conn, DBusMessage *msg, void *data) { struct serial_adapter *adapter = data; struct serial_proxy *proxy; const char *pattern, *address; char *uuid_str; int err; if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID)) return NULL; uuid_str = bt_name2string(pattern); if (!uuid_str) return invalid_arguments(msg, "Invalid UUID"); err = register_proxy(adapter, uuid_str, address, &proxy); g_free(uuid_str); if (err == -EINVAL) return invalid_arguments(msg, "Invalid address"); else if (err == -EALREADY) return g_dbus_create_error(msg, ERROR_INTERFACE ".AlreadyExist", "Proxy already exists"); else if (err < 0) return g_dbus_create_error(msg, ERROR_INTERFACE "Failed", "Proxy creation failed (%s)", strerror(-err)); proxy->owner = g_strdup(dbus_message_get_sender(msg)); proxy->watch = g_dbus_add_disconnect_watch(conn, proxy->owner, watch_proxy, proxy, NULL); return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &proxy->path, DBUS_TYPE_INVALID); }
static void serial_proxy_init(struct serial_adapter *adapter) { GKeyFile *config; GError *gerr = NULL; const char *file = CONFIGDIR "/serial.conf"; char **group_list; int i; config = g_key_file_new(); if (!g_key_file_load_from_file(config, file, 0, &gerr)) { error("Parsing %s failed: %s", file, gerr->message); g_error_free(gerr); g_key_file_free(config); return; } group_list = g_key_file_get_groups(config, NULL); for (i = 0; group_list[i] != NULL; i++) { char *group_str = group_list[i], *uuid_str, *address; int err; struct serial_proxy *prx; /* string length of "Proxy" is 5 */ if (strlen(group_str) < 5 || strncmp(group_str, "Proxy", 5)) continue; uuid_str = g_key_file_get_string(config, group_str, "UUID", &gerr); if (gerr) { debug("%s: %s", file, gerr->message); g_error_free(gerr); g_key_file_free(config); return; } address = g_key_file_get_string(config, group_str, "Address", &gerr); if (gerr) { debug("%s: %s", file, gerr->message); g_error_free(gerr); g_key_file_free(config); g_free(uuid_str); return; } err = register_proxy(adapter, uuid_str, address, &prx); if (err == -EINVAL) error("Invalid address."); else if (err == -EALREADY) debug("Proxy already exists."); else if (err < 0) error("Proxy creation failed (%s)", strerror(-err)); else { err = enable_proxy(prx); if (err < 0) error("Proxy enable failed (%s)", strerror(-err)); } g_free(uuid_str); g_free(address); } g_strfreev(group_list); g_key_file_free(config); }