static void compare_sec_rs_finalize(SocketReadState *sec_rs) { CompareState *s = container_of(sec_rs, CompareState, sec_rs); Connection *conn = NULL; if (packet_enqueue(s, SECONDARY_IN, &conn)) { trace_colo_compare_main("secondary: unsupported packet in"); } else { /* compare packet in the specified connection */ colo_compare_connection(conn, s); } }
static void compare_pri_rs_finalize(SocketReadState *pri_rs) { CompareState *s = container_of(pri_rs, CompareState, pri_rs); Connection *conn = NULL; if (packet_enqueue(s, PRIMARY_IN, &conn)) { trace_colo_compare_main("primary: unsupported packet in"); compare_chr_send(s, pri_rs->buf, pri_rs->packet_len, pri_rs->vnet_hdr_len); } else { /* compare packet in the specified connection */ colo_compare_connection(conn, s); } }
void print_console (Emulator *emu, char *buf) { packet_enqueue(emu, buf, strlen(buf) + 1, CONSOLE_PACKET_OPCODE); }
void *web_server (void *ctxt) { emu = (Emulator *) ctxt; Debugger *deb = emu->debugger; int port = 9001; //struct libwebsocket_context *context; struct lws_context *context; struct lws_context_creation_info context_info = { .port = deb->ws_port, //port, .iface = NULL, .protocols = protocols, .extensions = NULL, .ssl_cert_filepath = NULL, .ssl_private_key_filepath = NULL, .ssl_ca_filepath = NULL, .gid = -1, .uid = -1, .options = 0, NULL, .ka_time = false, .ka_probes = false, .ka_interval = false }; // Initialize packet queuing system init_packet_queue(emu); // create libwebsocket context representing this server context = lws_create_context(&context_info); if (context == NULL) { fprintf(stderr, "libwebsocket init failed\n"); deb->quit = true; exit(1); } printf("starting server...\n"); while (true) { lws_service(context, 10); // ms usleep(1000); } lws_context_destroy(context); return NULL; } void send_control(Emulator *emu, uint8_t opcode, void *data, size_t data_size) { const static uint8_t NUM_OPCODE_BYTES = 1; const static uint8_t NUM_DATA_LEN_BYTES = 1; if (data == NULL) { // Simple case packet_enqueue(emu, (void *)&opcode, 1, CONTROL_PACKET_OPCODE); } else { // data case ( OP DL DATADATADATA ) uint8_t full_packet[NUM_OPCODE_BYTES + NUM_DATA_LEN_BYTES + data_size]; // First part of packet is the opcode for specific control type memcpy(full_packet, (void *)&opcode, NUM_OPCODE_BYTES); // Second part is the data length field for following data memcpy(full_packet + NUM_OPCODE_BYTES, &data_size, NUM_DATA_LEN_BYTES); // Third part is the data itself. memcpy(full_packet + NUM_OPCODE_BYTES + NUM_DATA_LEN_BYTES, data, data_size); /* int i; for (i = 0;i < 1+size;i++) { printf("%02X ", *(uint8_t *)(full_packet + i)); } puts(" ."); */ packet_enqueue(emu, (void *)&full_packet, NUM_OPCODE_BYTES + NUM_DATA_LEN_BYTES + data_size, CONTROL_PACKET_OPCODE); } } void print_serial (Emulator *emu, char *buf) { packet_enqueue(emu, buf, strlen(buf) + 1, SERIAL_PACKET_OPCODE); }