Exemple #1
0
void receive_msg()
{
   unsigned int16 ip, lbody, index, pl;
   unsigned int8 msg[USB_EP1_RX_SIZE - 1], code, *body;
   unsigned int1 hasBody;
   
   usb_get_packet(1, msg, USB_EP1_RX_SIZE - 1);
   
   ip = (msg[0] + (msg[1] * 256));
   hasBody = bit_test(msg[2], 7);
   code = msg[2];
   bit_clear(code, 7);
  
#ifdef DEBUG_STREAM_A
   fprintf(A, "receive_msg IP: %Lu - Code: %u - HasBody: %u\n\r", ip, code, hasBody);
#endif

   if (hasBody)
   {
      lbody = (msg[3] + (msg[4] * 256));
      
      body = calloc(lbody - 1, sizeof(unsigned int8));
      
      pl = lbody;
      if (pl > USB_EP1_RX_SIZE - 6)
         pl = USB_EP1_RX_SIZE - 6;
      
      copy_array(msg, 5, body, 0, pl);
      index = pl;
      
      while(index < lbody - 1)
      {
         pl = lbody - index;
         if (pl > USB_EP1_RX_SIZE - 1)
            pl = USB_EP1_RX_SIZE - 1;
      
         while (!usb_kbhit(1));
         usb_get_packet(1, msg, USB_EP1_RX_SIZE - 1);
         copy_array(msg, 0, body, index, pl);

         index += pl;
      }
   
      process_msg(ip, code, lbody, body);
   
      if (body)
      {
         free(body);
      }
   }
   else
   {
      process_msg(ip, code, 0, body);
   }
}
Exemple #2
0
static void tcp_process(fd_set* set, vector_t* for_del)
{
    active_vector_iterator_t iter = active_vector_begin(&this.clients);
    while (!active_vector_is_end(iter))
    {
        client_t* client = iter.data;
        if (FD_ISSET(client->fd, set))
        {
            ssize_t rc = read_pre(client->fd, client->read, client->want);
            if (rc <= 0)
            {
                if (errno == EAGAIN || errno == EWOULDBLOCK) goto end;
                perror("read");
                vector_push_back(for_del, (void*)(long)active_vector_iterator_idx(iter), sizeof(active_vector_iterator_idx(iter)));
                goto end;
            }
            client->read += rc;
            client->want -= rc;
            if (client->want == 0)
            {
                if (IS_CLIENT_STATUS_WAITING_HEADER(client->status))
                {
                    size_t len = msg_data_length((msg_t*)client->buffer);
                    if (len)
                    {
                        msg_t* msg = (msg_t*)client->buffer;
                        client->status = (client->status & ~CLIENT_STATUS_WAITING_HEADER) | CLIENT_STATUS_WAITING_BODY;
                        if (msg->zone.clip)
                        {
                            if (msg->zone.last) client->want = len % client->max_length;
                            else client->want = client->max_length;
                        }
                        else client->want = len;
                        client->buffer_len = sizeof(msg_t) + client->want;
                        client->buffer = group_pool_room_realloc(&this.group_pool, client->buffer, sizeof(msg_t) + client->want);
                        if (client->buffer == NULL)
                        {
                            SYSLOG(LOG_ERR, "Not enough memory");
                            vector_push_back(for_del, (void*)(long)active_vector_iterator_idx(iter), sizeof(active_vector_iterator_idx(iter)));
                            exit(1);
                        }
                        client->read = ((msg_t*)client->buffer)->data;
                    }
                    else process_msg(client, (msg_t*)client->buffer, for_del, active_vector_iterator_idx(iter));
                }
                else process_msg(client, (msg_t*)client->buffer, for_del, active_vector_iterator_idx(iter));
            }
        }
        checkout_ttl(&client->recv_table);
end:
        iter = active_vector_next(iter);
    }
}
Exemple #3
0
void recv_func(void* arg)
{
	uint32_t user_id;
	struct msg_packet msg;
	while(1)
	{
		msg_recv(&msg);
		user_id = process_msg(&msg);

		switch (GET_MODE(msg.command))
		{
		case IPMSG_SENDMSG:
			console_clear_line(-1);
 			shell_recv_msg(user_id);
			printf("%s", buff);
			break;

		case IPMSG_ANSENTRY:
		case IPMSG_BR_ENTRY:
			shell_user_entry(user_id);

		case IPMSG_BR_EXIT:
			console_clear_line(-1);
			shell_user_exit(user_id, msg.msg);
			printf("%s", buff);
			break;
		}
	}
}
Exemple #4
0
void MainDlg::OnRecvMsg()
{
	char buff[1024] = {0};
	uint32_t user_id;
	struct msg_packet msg;

	while(1)
	{
		msg_recv(&msg);
		user_id = process_msg(&msg);

		switch (GET_MODE(msg.command))
		{
		case IPMSG_SENDMSG:
			break;

		case IPMSG_ANSENTRY:
		case IPMSG_BR_ENTRY:
			OnFriendOnline(user_find(user_id));
			break;

		case IPMSG_BR_EXIT:
			break;
		}
	}
}
Exemple #5
0
int main(int argc, char *argv[])
{
    if (argc != 2) {
        fprintf(stderr,"usage: client hostname\n");
        exit(1);
    }

    read_cfg(COMMON_CFG_PATH);      //to find bitfield length

    struct peer_info info;
    strcpy(info.hostname, argv[1]);
    strcpy(info.port, PORT);

    int s = make_socket_to_peer(&info);
    if (s == -1) {
        fprintf(stderr, "client: make_socket_to_peer() failed");
        exit(1);
    }

    unsigned int payload_len;
    message_t type;
    unsigned char payload[5000];

    int i;
    for (i = 0 ; i < 8 ; i++)
    {
        type = recv_msg(info.from_fd, &payload_len, payload);
        process_msg(payload, payload_len, type);
        printf("\n");
    }

    close(info.from_fd);

    return 0;
}
Exemple #6
0
int rcv_packet(int sock_raw, char *buffers, struct hdr_histogram *hist)
{
    struct mmsghdr msgs[NUM_BUFFERS];
    struct iovec entries[NUM_BUFFERS];
    struct {
        struct cmsghdr cm;
        char control[512];
    } control[NUM_BUFFERS];
    struct timespec timeout;
    int valid_pkts = 0;
    int npkts = 0;

    memset(&timeout, 0, sizeof(timeout));
    memset(msgs, 0, sizeof(msgs));
    for (int i = 0; i < NUM_BUFFERS; ++i) {
        entries[i].iov_base = &buffers[i * BUFFER_SIZE];
        entries[i].iov_len = BUFFER_SIZE;
        msgs[i].msg_hdr.msg_iov = &entries[i];
        msgs[i].msg_hdr.msg_iovlen = 1;
        msgs[i].msg_hdr.msg_control = &control[i];
        msgs[i].msg_hdr.msg_controllen = sizeof(control[i]);
    }

    npkts = recvmmsg(sock_raw, msgs, NUM_BUFFERS, MSG_WAITFORONE, &timeout);
    if (npkts < 0) {
        perror("recvmmsg()");
        return 0;
    }

    for (int i = 0; i < npkts; ++i) {
        if (process_msg(&msgs[i].msg_hdr, &buffers[i * BUFFER_SIZE], hist))
            valid_pkts += 1;
    }
    return valid_pkts;
}
Exemple #7
0
static void on_read(int fd, void *arg)
{
    struct rpc *r = (struct rpc *)arg;
    char out_arg[1024];
    struct iovec *recv_buf;
    uint32_t msg_id;
    size_t out_len;
    memset(&r->recv_pkt, 0, sizeof(struct rpc_packet));

    recv_buf = rpc_recv_buf(r);
    if (!recv_buf) {
        loge("rpc_recv_buf failed!\n");
        return;
    }

    struct rpc_packet *pkt = &r->recv_pkt;
    unpack_msg(pkt, &msg_id, &out_arg, &out_len);
    logi("msg_id = %08x\n", msg_id);

    if (r->state == rpc_inited) {
        r->send_pkt.header.uuid_src = *(uint32_t *)pkt->payload;
        thread_sem_signal(r->dispatch_thread);
        r->state = rpc_connected;
    } else if (r->state == rpc_connected) {
        struct iovec buf;
        buf.iov_len = pkt->header.payload_len;
        buf.iov_base = pkt->payload;
        process_msg(r, &buf);
        //free(pkt->payload);
        thread_sem_signal(r->dispatch_thread);
    }
}
Exemple #8
0
static void *thread_entry(void *arg)
{
    int rv;
    store_client_t *sc = (store_client_t *)arg;
    net_client_t *nc = sc->nc;
    void *msg;uint32_t len;

    while(!sc->stop_daemon)
    {
	rv = nc_recvmsg(nc,&msg,&len,MS_PER_SECOND/4);
	if(rv < 0)
	    continue;
	if(rv == 0)
	{
	    process_msg(msg,len);
	    //process msg
	    nc_free(nc,msg);
	}
	if(rv == 1)
	{
	    //disconnect
	}
    }
    return NULL;
}
Exemple #9
0
static void
intr_mbox(void *arg)
{
	struct tegra_xhci_softc *sc;
	uint32_t reg, msg, resp_cmd, resp_data;

	sc = (struct tegra_xhci_softc *)arg;

	/* Clear interrupt first */
	reg = FPCI_RD4(sc, XUSB_CFG_ARU_SMI_INTR);
	FPCI_WR4(sc, XUSB_CFG_ARU_SMI_INTR, reg);
	if (reg & ARU_SMI_INTR_FW_HANG) {
		device_printf(sc->dev,
		    "XUSB CPU firmware hang!!! CPUCTL: 0x%08X\n",
		    CSB_RD4(sc, XUSB_FALCON_CPUCTL));
	}

	msg = FPCI_RD4(sc, T_XUSB_CFG_ARU_MAILBOX_DATA_OUT);
	resp_cmd = 0;
	process_msg(sc, ARU_MAILBOX_DATA_OUT_TYPE(msg),
	   ARU_MAILBOX_DATA_OUT_DATA(msg), &resp_cmd, &resp_data);
	if (resp_cmd != 0)
		mbox_send_ack(sc, resp_cmd, resp_data);
	else
		FPCI_WR4(sc, T_XUSB_CFG_ARU_MAILBOX_OWNER,
		    ARU_MAILBOX_OWNER_NONE);

	reg = FPCI_RD4(sc, T_XUSB_CFG_ARU_MAILBOX_CMD);
	reg &= ~ARU_MAILBOX_CMD_DEST_SMI;
	FPCI_WR4(sc, T_XUSB_CFG_ARU_MAILBOX_CMD, reg);

}
Exemple #10
0
void on_recv(int fd, void *arg)
{
    struct iobuf *buf;
    char key[9];
    snprintf(key, sizeof(key), "%08x", fd);
    struct rpc *r = (struct rpc *)dict_get(_rpcd->dict_fd2rpc, key, NULL);
    if (!r) {
        loge("dict_get failed: key=%s", key);
        return;
    }
    //logi("on_recv fd = %d dict_get: key=%s, r->fd=%d\n", fd, key, r->fd);
    buf = rpc_recv_buf(r);
    if (!buf) {
        //loge("peer connect closed\n");
        rpc_connect_destroy(_rpcd, r);
        return;
    }
    process_msg(r, buf);
    r->fd = fd;//must be reset
    //dump_buffer(buf->addr, buf->len);
    //dump_packet(&r->packet);

    free(buf->addr);
    free(buf);
}
Exemple #11
0
int main(void)
{
	mcusr_save = MCUSR;
	MCUSR = 0;
	wdt_disable();
	if (!(mcusr_save & WDRF))
	{
		seqnum = 0;
	}
	
#ifdef SN_TEMP_DDR
	// configure pin for analog
	SN_TEMP_DDR &= ~SN_TEMP_MASK; // set as input
	SN_TEMP_PORT &= ~SN_TEMP_MASK;	// pull-ups off
	DIDR0 |= SN_TEMP_MASK; // disable digital input buffer
#endif
	SN_LED_DDR |= SN_LED_MASK; // set as output
	SN_LED_PORT &= ~SN_LED_MASK;
	vw_setup();
#ifdef SN_RX_CAPABLE
	vw_rx_start();
#endif
	for (int i=0;i<3;i++)
	{
		send_status(SN_ADDRESS_BROADCAST);
		vw_wait_tx();
	}
	for (;;) {
#ifdef SN_RX_CAPABLE
		if (vw_have_message()) {
			uint8_t len = sizeof(msg);
			if (vw_get_message((uint8_t *)&msg, &len)) {
				if (msg.header.destination == SN_ADDRESS_ME|| msg.header.destination == SN_ADDRESS_BROADCAST) {
					process_msg();
				} else {
					// TODO - consider routing here
				}
			} else {
				// bad message
			}
		}
#endif
#ifdef SN_TX_CAPABLE
		// Process any outgoing stuff
		if (millis() - last_status > STATUS_PERIOD) {
			send_status(SN_ADDRESS_BROADCAST);
		}
		if (millis() - last_sensor_data > SENSOR_PERIOD) {
			send_sensor_data(SN_ADDRESS_BROADCAST);
		}
#endif // SN_TX_CAPABLE
#ifdef USE_MILLIS
		//set_sleep_mode(SLEEP_MODE_IDLE);
		//sleep_enable();
		//sleep_cpu();
		//sleep_disable();
#endif
	}
}
void onUSBCommTask(void *pvParameters)
{
        while (1) {
                if (USB_CDC_is_initialized())
                        process_msg(get_serial(SERIAL_USB), lineBuffer, BUFFER_SIZE);
                taskYIELD();
        }
}
Exemple #13
0
static int get_body(void *msg) {
	int answ = process_msg((struct bc_msg_body *) msg);
	if (answ == 0) {
		data_hnd = get_length;
		bluetooth_read(1);
	}

	return NET_HND_STOP_FREE;
}
Exemple #14
0
void process_udp_msg(struct local_msg *m, struct sockaddr_in *addr) {
	int i;
	switch (m->c) {
		case 0: process_msg(m); break;
		case 1: case 2: 
			i = udp_check_client(&tmpaddress);
			if (i<0) { //new client
				i=udp_add_client(&tmpaddress);
			}
			if (m->c==2) ping_back(m,addr);
			else process_msg(m);
			break;
		case 3:
			local_buf[local_buf_c++] = *m;
			break;
		default: printf("Unknown UDP control: %u\n",m->c);
	}
}
static void turnserver_udp_recv(const struct sa *src, struct mbuf *mb,
				void *arg)
{
	TurnServer *turn = static_cast<TurnServer *>(arg);

	turn->nrecv++;

	process_msg(turn->turnd, IPPROTO_UDP, turn->us, src, &turn->addr, mb);
}
static void
nmsg_callback(nmsg_message_t msg, void *user) {
	if (nmsg_message_get_vid(msg) == NMSG_VENDOR_BASE_ID &&
	    nmsg_message_get_msgtype(msg) == NMSG_VENDOR_BASE_PKT_ID)
	{
		process_msg(msg);
	}

	nmsg_message_destroy(&msg);
}
Exemple #17
0
int process_select(struct srv_connection *conn, struct select s_val, FILE* file, int* count){
	int i;
	for (i=0; i<conn->cli_ct; i++){
			
		if (!FD_ISSET(conn->cli[i].sfd, &(s_val.readfds)))
			continue;
		
		process_msg(&(conn->cli[i]), file, count);
	}
}
Exemple #18
0
static void* udp_recv_thread_func(void * arg) {
	topic_subscription_pt sub = (topic_subscription_pt) arg;

#if defined(__APPLE__) && defined(__MACH__)
	//TODO: use kqueue for OSX
	//struct kevent events[MAX_EPOLL_EVENTS];
	while (sub->running) {
		int nfds = 0;
		if(nfds > 0) {
			pubsub_udp_msg_t* udpMsg = NULL;
			process_msg(sub, udpMsg);
		}
	}
#else
	struct epoll_event events[MAX_EPOLL_EVENTS];

	while (sub->running) {
		int nfds = epoll_wait(sub->topicEpollFd, events, MAX_EPOLL_EVENTS, RECV_THREAD_TIMEOUT * 1000);
		int i;
		for(i = 0; i < nfds; i++ ) {
			unsigned int index;
			unsigned int size;
			if(largeUdp_dataAvailable(sub->largeUdpHandle, events[i].data.fd, &index, &size) == true) {
				// Handle data
				pubsub_udp_msg_t *udpMsg = NULL;
				if(largeUdp_read(sub->largeUdpHandle, index, (void**)&udpMsg, size) != 0) {
					printf("PSA_UDP_MC_TS: ERROR largeUdp_read with index %d\n", index);
					continue;
				}

				process_msg(sub, udpMsg);

				free(udpMsg);
			}
		}
		connectPendingPublishers(sub);
		disconnectPendingPublishers(sub);
	}
#endif

	return NULL;
}
Exemple #19
0
void on_rpc_read(int fd, void *arg)
{
    struct p2p *p2p = (struct p2p *)arg;
    struct rpc *r = p2p->rpc;
    struct iovec *buf = rpc_recv_buf(r);
    if (!buf) {
        logi("rpc_recv_buf failed!\n");
        return;
    }
    process_msg(r, buf);
}
Exemple #20
0
int main(int argc, char** argv)
{
    int erl_fd; // FD to the ERL VM
    char* bufp; // storage for incoming messages
    int bufsz = 1024;

    // the following are basically magic values.
    erl_fd = setup_connection(1, "secretcookie", 0, "e1@am335x-evm");

    ErlMessage* emsg;
    emsg = (ErlMessage*)malloc(sizeof(ErlMessage));
    bufp = (char*)malloc(bufsz * sizeof(char));

    while (1) // main loop - we don't ever expect to leave.
    {
        TRACE(("starting main loop"));

        TRACE(("waiting for a message..."));
        int msg_status = erl_receive_msg(erl_fd, bufp, bufsz, emsg);
        TRACE(("got a message"));

        switch (msg_status)
        {
        case (ERL_MSG): 
            TRACE(("message status is ERL_MSG"));
            process_msg(emsg, erl_fd);
            break;
        case (ERL_TICK):
            TRACE(("message status is ERL_TICK"));
            break;
        case (ERL_ERROR):
        default:
            TRACE(("message status is ERL_ERROR"));
            process_error();
            break;
        }

        TRACE(("cleaning up at end of main loop"));
        erl_free_term(emsg->msg);
        erl_free_term(emsg->from);
        erl_free_term(emsg->to);

    } // end while loop

    if (erl_close_connection(erl_fd) < 0)
    {
        perror("failed to close connection. plowing onward.");
    }

    free(emsg);
    free(bufp);

}
void kct_netlink_handle_msg(void) {

    struct kct_packet *msg;

    msg = netlink_get_packet(sock_nl_fd);
    if (msg == NULL) {
        LOGE("Could not receive kernel packet: %s", strerror(errno));
        return;
    }

    /* Process Kernel message */
    process_msg(&msg->event);
    free(msg);
}
Exemple #22
0
static gboolean
xmms_ipc_client_read_cb (GIOChannel *iochan,
                         GIOCondition cond,
                         gpointer data)
{
	xmms_ipc_client_t *client = data;
	bool disconnect = FALSE;

	g_return_val_if_fail (client, FALSE);

	if (cond & G_IO_IN) {
		while (TRUE) {
			if (!client->read_msg) {
				client->read_msg = xmms_ipc_msg_alloc ();
			}

			if (xmms_ipc_msg_read_transport (client->read_msg, client->transport, &disconnect)) {
				xmms_ipc_msg_t *msg = client->read_msg;
				client->read_msg = NULL;
				process_msg (client, msg);
				xmms_ipc_msg_destroy (msg);
			} else {
				break;
			}
		}
	}

	if (disconnect || (cond & G_IO_HUP)) {
		if (client->read_msg) {
			xmms_ipc_msg_destroy (client->read_msg);
			client->read_msg = NULL;
		}
		XMMS_DBG ("disconnect was true!");
		g_main_loop_quit (client->ml);
		return FALSE;
	}

	if (cond & G_IO_ERR) {
		xmms_log_error ("Client got error, maybe connection died?");
		g_main_loop_quit (client->ml);
		return FALSE;
	}

	return TRUE;
}
int main(int argc, const char *argv[])
{
	init_function *fun;
	int id;
	//init
	signal(SIGPIPE,SIG_IGN);
	callback_tab["list"] = list;
	callback_tab["close"] = close;
	msg_t config = get_config_from_file("config.json");
	sock::init(config);
	for(fun = &__initlist_start;fun < &__initlist_end;fun++)
		assert_perror((*fun)(config) < 0);

	//main message loop
	while(get_msg_source(id)){
		process_msg(id);
	}

	return 0;
}
Exemple #24
0
static void *mainloop(void *arg)
{
	printf("start io thread\n");
    struct poller_st *n = (struct poller_st *)arg;
	while(0 == n->flag)
	{
		uint64_t tick = GetSystemMs64();
        uint64_t timeout = tick + 10;
		int8_t is_empty = 0;
		for(;tick < timeout;){
            lnode *node = NULL;
			msgque_get(n->mq_in,&node,0);
			if(node)
			{
				msg_t msg = (msg_t)node;
				if(msg->type == MSG_WPACKET)
				{
					//发送数据包
					process_send(n,(wpacket_t)msg);
				}else
				{
					process_msg(n,msg);
				}
			}
			else{
				is_empty = 1;
				break;
			}
			tick = GetSystemMs64();
		}
		if(is_empty){
			//注册中断器,如果阻塞在loop里时mq_in收到消息会调用唤醒函数唤醒loop
			msgque_putinterrupt(n->mq_in,(void*)n->netpoller,notify_function);
            n->netpoller->loop(n->netpoller,10);
			msgque_removeinterrupt(n->mq_in);
		}
		else
			n->netpoller->loop(n->netpoller,0);
	}
	return NULL;
}
Exemple #25
0
void conn_listen(int *socket) {
  char *buffer, *resp;
  int res;
  // repeatedly respond to lines sent by the client
  do {
    // receive a string from this client's connection socket
    res = recv_message(*socket, &buffer);
    if (res < 0) {
      send_string(*socket, "NACK");
      continue;
    }

    resp = process_msg(buffer);

//    printf("Client says \"%s\".\nResponding \"%s\"\n", buffer, resp);
    printf("Responding \"%s\"\n", resp);

    send_message(*socket, resp); // Note that process_msg() may have side effects.
  } while (res > 0 && strcmp(buffer,"STOP"));
  close(*socket);
}
Exemple #26
0
static u8_t *recv_cb(u8_t *buf, size_t *off)
{
	struct slip_context *slip =
		CONTAINER_OF(buf, struct slip_context, buf);
	size_t i;

	if (!slip->init_done) {
		*off = 0;
		return buf;
	}

	for (i = 0; i < *off; i++) {
		if (slip_input_byte(slip, buf[i])) {
#if SYS_LOG_LEVEL >= SYS_LOG_LEVEL_DEBUG
			struct net_buf *frag = slip->rx->frags;
			int bytes = net_buf_frags_len(frag);
			int count = 0;

			while (bytes && frag) {
				char msg[8 + 1];

				snprintf(msg, sizeof(msg), ">slip %2d", count);

				hexdump(msg, frag->data, frag->len, 0);

				frag = frag->frags;
				count++;
			}

			SYS_LOG_DBG("[%p] received data %d bytes", slip, bytes);
#endif
			process_msg(slip);
			break;
		}
	}

	*off = 0;

	return buf;
}
Exemple #27
0
int main(int argc, char **argv)
{
	int msgid;
	msgbuf_st msgbuf;

	if (-1 == (msgid = msgget(KEY_VALUE, IPC_CREAT | 0666)))
		ERROR_EXIT("msgget");

	gpio_setup();

	msgbuf.mtype = MSG_TYPE;
	while(1) {
		if (-1 == msgrcv(msgid, &msgbuf, sizeof(msgbuf_st) - sizeof(long), msgbuf.mtype, 0))
			ERROR_EXIT("msgrcv");

		printf("Recv message:%s\n", msgbuf.minfo);
		process_msg(msgbuf.minfo);
	}
	gpio_cleanup();

	return 0;
}
Exemple #28
0
static char*  
process_command(int argc, char * argv[])
{
	char *msg = NULL, *result = NULL;
	int i;
	char *buf = NULL;

	msg = mgmt_new_msg(argv[1], NULL);
	for(i = 2; i < argc; i++ ) {
		msg = mgmt_msg_append(msg, argv[i]);
	}

	cl_log(LOG_DEBUG, "msg sent: %s", msg);
	result = process_msg(msg);
	mgmt_del_msg(msg);
	if ( result == NULL ) {
		return NULL;
	}
	buf = cl_strdup(result);
	mgmt_del_msg(result);
	return buf;
}
Exemple #29
0
void process_socket_queue(int client) {
	int msg_c = buf_c[client] / LOCAL_MSG_SIZE;
	int msg_r = buf_c[client] % LOCAL_MSG_SIZE;
	struct local_msg m;

	for (int i=0;i<msg_c;i++) {
		unpack_lm(buf[client]+i*LOCAL_MSG_SIZE,&m);
		switch (m.c) {
			case 0: process_msg(&m); break;
			case 3: 
				local_buf[local_buf_c++] = m;
			break;
			default: printf("Unknown SOCKET control: %u\n",m.c);
		}
	}

	if (msg_c) {
		for (int i=0;i<msg_r;i++)
			buf[client][i] = buf[client][msg_c*LOCAL_MSG_SIZE+i];
		buf_c[client] = msg_r;
	}
}
Exemple #30
0
static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
{
    IVShmemState *s = opaque;
    Error *err = NULL;
    int fd;
    int64_t msg;

    assert(size >= 0 && s->msg_buffered_bytes + size <= sizeof(s->msg_buf));
    memcpy((unsigned char *)&s->msg_buf + s->msg_buffered_bytes, buf, size);
    s->msg_buffered_bytes += size;
    if (s->msg_buffered_bytes < sizeof(s->msg_buf)) {
        return;
    }
    msg = le64_to_cpu(s->msg_buf);
    s->msg_buffered_bytes = 0;

    fd = qemu_chr_fe_get_msgfd(&s->server_chr);

    process_msg(s, msg, fd, &err);
    if (err) {
        error_report_err(err);
    }
}