}
-static int socket_initialize(ECS_State *cs, QemuOpts *opts) {
- int fd = -1;
- Error *local_err = NULL;
-
- fd = inet_listen_opts(opts, 0, &local_err);
- if (0 > fd || local_err) {
- qerror_report_err(local_err);
- error_free(local_err);
- return -1;
- }
-
- INFO("Listen fd is %d\n", fd);
-
- qemu_set_nonblock(fd);
-
- cs->listen_fd = fd;
-
-#ifdef CONFIG_LINUX
- epoll_init(cs);
-#else
- FD_ZERO(&cs->reads);
- FD_SET(fd, &cs->reads);
-#endif
-
- make_keep_alive_msg();
-
- cs->alive_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, alive_checker, cs);
-
- timer_mod(cs->alive_timer,
- qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + get_ticks_per_sec() * TIMER_ALIVE_S);
-
- return 0;
-}
-
#ifdef CONFIG_LINUX
static int ecs_loop(ECS_State *cs) {
int i, nfds;
#endif
+static int ecs_socket_listen(int port)
+{
+ struct sockaddr_in addr;
+ int slisten = -1;
+ int ret = -1;
+
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(port);
+
+ ret = inet_aton(HOST_LISTEN_ADDR, &addr.sin_addr);
+ if (ret == 0) {
+ ERR("inet_aton failure\n");
+ return -1;
+ }
+
+ slisten = qemu_socket(PF_INET, SOCK_STREAM, 0);
+ if (slisten < 0) {
+ ERR("socket creation failed.\n");
+ return slisten;
+ }
+
+ ret = socket_set_fast_reuse(slisten);
+ if (ret != 0) {
+ ERR("It cannot be reach here.\n");
+ closesocket(slisten);
+ return -1;
+ }
+
+ if (bind(slisten, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ ERR("bind failed : %d\n", errno);
+ closesocket(slisten);
+ return -1;
+ }
+
+ if (listen(slisten,1) != 0) {
+ ERR("listen failed : %d\n", errno);
+ closesocket(slisten);
+ return -1;
+ }
+
+ return slisten;
+}
+
+static int socket_initialize(ECS_State *cs, int port) {
+ int fd = -1;
+
+ fd = ecs_socket_listen(port);
+ if (fd < 0) {
+ return -1;
+ }
+
+ INFO("Listen fd is %d\n", fd);
+
+ qemu_set_nonblock(fd);
+
+ cs->listen_fd = fd;
+
+#ifdef CONFIG_LINUX
+ epoll_init(cs);
+#else
+ FD_ZERO(&cs->reads);
+ FD_SET(fd, &cs->reads);
+#endif
+
+ make_keep_alive_msg();
+
+ cs->alive_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, alive_checker, cs);
+
+ timer_mod(cs->alive_timer,
+ qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + get_ticks_per_sec() * TIMER_ALIVE_S);
+
+ return 0;
+}
+
static void* ecs_initialize(void* args) {
int ret = 1;
ECS_State *cs = NULL;
- QemuOpts *opts = NULL;
- Error *local_err = NULL;
Monitor* mon = NULL;
- char host_port[16];
int port = 0;
INFO("ecs starts initializing.\n");
qemu_mutex_init(&mutex_clilist);
qemu_mutex_init(&mutex_location_data);
- opts = qemu_opts_create(qemu_find_opts(ECS_OPTS_NAME), ECS_OPTS_NAME, 1, &local_err);
- if (local_err) {
- qerror_report_err(local_err);
- error_free(local_err);
- return NULL;
- }
-
- qemu_opt_set(opts, "host", HOST_LISTEN_ADDR);
- qemu_opt_set_bool(opts, "ipv4", true);
-
cs = g_malloc0(sizeof(ECS_State));
if (NULL == cs) {
ERR("ECS_State allocation failed.\n");
cs->listen_fd = -1;
port = get_emul_ecs_port();
- INFO("ecs port: %d\n", port);
- sprintf(host_port, "%d", port);
- qemu_opt_set(opts, "port", host_port);
- ret = socket_initialize(cs, opts);
+ ret = socket_initialize(cs, port);
if (ret < 0) {
ERR("Socket initialization is failed.\n");
ecs_close(cs);
static Notifier ecs_exit = { .notify = ecs_notify_exit };
int start_ecs(void) {
- qemu_add_opts(&qemu_ecs_opts);
-
qemu_thread_create(&ecs_thread_id, "ecs", ecs_initialize, NULL, QEMU_THREAD_JOINABLE);
emulator_add_exit_notifier(&ecs_exit);
#include "genmsg/ecs.pb-c.h"
#include "genmsg/ecs_ids.pb-c.h"
-#define ECS_VERSION "1.0"
-
-#define ECS_OPTS_NAME "ecs"
#define HOST_LISTEN_ADDR "127.0.0.1"
-#define HOST_LISTEN_PORT 0
-#define EMULATOR_SERVER_NUM 10
#define COMMANDS_TYPE "type"
#define COMMANDS_DATA "data"
-
#define COMMAND_TYPE_INJECTOR "injector"
#define COMMAND_TYPE_CONTROL "control"
#define COMMAND_TYPE_MONITOR "monitor"
/* Monitor */
void handle_qmp_command(JSONMessageParser *parser, QList *tokens, void *opaque);
-static QemuOptsList qemu_ecs_opts = {
- .name = ECS_OPTS_NAME,
- .implied_opt_name = ECS_OPTS_NAME,
- .head = QTAILQ_HEAD_INITIALIZER(qemu_ecs_opts.head),
- .desc = {
- {
- .name = "host",
- .type = QEMU_OPT_STRING,
- },{
- .name = "port",
- .type = QEMU_OPT_STRING,
- },{
- .name = "localaddr",
- .type = QEMU_OPT_STRING,
- },{
- .name = "localport",
- .type = QEMU_OPT_STRING,
- },{
- .name = "to",
- .type = QEMU_OPT_NUMBER,
- },{
- .name = "ipv4",
- .type = QEMU_OPT_BOOL,
- },{
- .name = "ipv6",
- .type = QEMU_OPT_BOOL,
- },
- { /* End of list */ }
- },
-};
-
#endif /* __ECS_H__ */