int main(int argc, char *argv[]) { helix_session_t session; struct sockaddr_in addr; helix_protocol_t proto; struct config cfg = {}; uv_udp_t socket; int err; program = basename(argv[0]); parse_options(&cfg, argc, argv); if (!cfg.symbol) { fprintf(stderr, "error: symbol is not specified. Use the '-s' option to specify it.\n"); exit(1); } if (!cfg.multicast_proto) { fprintf(stderr, "error: multicast protocol is not specified. Use the '-c' option to specify it.\n"); exit(1); } if (!cfg.multicast_addr) { fprintf(stderr, "error: multicast address is not specified. Use the '-a' option to specify it.\n"); exit(1); } if (!cfg.multicast_port) { fprintf(stderr, "error: multicast port is not specified. Use the '-p' option to specify it.\n"); exit(1); } if (!strcmp(cfg.format, "pretty")) { fmt_ops = &fmt_pretty_ops; } else if (!strcmp(cfg.format, "csv")) { fmt_ops = &fmt_csv_ops; } else { fprintf(stderr, "error: %s: unsupported format\n", cfg.format); exit(1); } if (cfg.output) { output = fopen(cfg.output, "w"); if (!output) { fprintf(stderr, "error: %s: %s\n", cfg.output, strerror(errno)); exit(1); } } else { output = stdout; } proto = helix_protocol_lookup(cfg.multicast_proto); if (!proto) { fprintf(stderr, "error: protocol '%s' is not supported\n", cfg.multicast_proto); exit(1); } session = helix_session_create(proto, cfg.symbol, process_ob_event, process_trade_event, NULL); if (!session) { fprintf(stderr, "error: unable to create new session\n"); exit(1); } err = uv_udp_init(uv_default_loop(), &socket); if (err) { libuv_error("uv_udp_init", err); } socket.data = session; err = uv_ip4_addr("0.0.0.0", cfg.multicast_port, &addr); if (err) { libuv_error("uv_ip4_addr", err); } err = uv_udp_bind(&socket, (const struct sockaddr *)&addr, UV_UDP_REUSEADDR); if (err) { libuv_error("uv_udp_bind", err); } err = uv_udp_set_membership(&socket, cfg.multicast_addr, NULL, UV_JOIN_GROUP); if (err) { libuv_error("uv_udp_set_membership", err); } err = uv_udp_recv_start(&socket, alloc_packet, recv_packet); if (err) { libuv_error("uv_udp_recv_start", err); } fmt_ops->fmt_header(); uv_run(uv_default_loop(), UV_RUN_DEFAULT); }
int main(int argc, char *argv[]) { helix_session_t session; struct sockaddr_in addr; helix_protocol_t proto; struct config cfg = {}; uv_udp_t socket; int err; program = basename(argv[0]); parse_options(&cfg, argc, argv); if (!cfg.symbol) { fprintf(stderr, "error: symbol is not specified. Use the '-s' option to specify it.\n"); exit(1); } if (!cfg.proto) { fprintf(stderr, "error: multicast protocol is not specified. Use the '-P' option to specify it.\n"); exit(1); } if (!cfg.multicast_addr) { fprintf(stderr, "error: multicast address is not specified. Use the '-a' option to specify it.\n"); exit(1); } if (!cfg.multicast_port) { fprintf(stderr, "error: multicast port is not specified. Use the '-p' option to specify it.\n"); exit(1); } proto = helix_protocol_lookup(cfg.proto); if (!proto) { fprintf(stderr, "error: protocol '%s' is not supported\n", cfg.proto); exit(1); } session = helix_session_create(proto, process_ob_event, process_trade_event, NULL); if (!session) { fprintf(stderr, "error: unable to create new session\n"); exit(1); } helix_session_subscribe(session, cfg.symbol, cfg.max_orders); err = uv_udp_init(uv_default_loop(), &socket); if (err) { libuv_error("uv_udp_init", err); } socket.data = session; err = uv_ip4_addr("0.0.0.0", cfg.multicast_port, &addr); if (err) { libuv_error("uv_ip4_addr", err); } err = uv_udp_bind(&socket, (const struct sockaddr *)&addr, UV_UDP_REUSEADDR); if (err) { libuv_error("uv_udp_bind", err); } err = uv_udp_set_membership(&socket, cfg.multicast_addr, NULL, UV_JOIN_GROUP); if (err) { libuv_error("uv_udp_set_membership", err); } err = uv_udp_recv_start(&socket, alloc_packet, recv_packet); if (err) { libuv_error("uv_udp_recv_start", err); } initscr(); clear(); refresh(); uv_run(uv_default_loop(), UV_RUN_DEFAULT); endwin(); return 0; }