static int pico_mock_poll(struct pico_device *dev, int loop_score) { struct mock_device search = { .dev = dev }; struct mock_device*mock = pico_tree_findKey(&mock_device_tree, &search); struct mock_frame*nxt; if(!mock) return 0; if (loop_score <= 0) return 0; while(mock->in_head != NULL && loop_score > 0) { pico_stack_recv(dev, mock->in_head->buffer, (uint32_t)mock->in_head->len); loop_score--; PICO_FREE(mock->in_head->buffer); if(mock->in_tail == mock->in_head) { PICO_FREE(mock->in_head); mock->in_tail = mock->in_head = NULL; return loop_score; } nxt = mock->in_head->next; PICO_FREE(mock->in_head); mock->in_head = nxt; } return loop_score; }
static int pico_ipc_poll(struct pico_device *dev, int loop_score) { struct pico_device_ipc *ipc = (struct pico_device_ipc *) dev; struct pollfd pfd; unsigned char buf[IPC_MTU]; int len; pfd.fd = ipc->fd; pfd.events = POLLIN; do { if (poll(&pfd, 1, 0) <= 0) return loop_score; len = (int)read(ipc->fd, buf, IPC_MTU); if (len > 0) { loop_score--; pico_stack_recv(dev, buf, (uint32_t)len); } } while(loop_score > 0); return 0; }
static int pico_tun_poll(struct pico_device *dev, int loop_score) { struct pico_device_tun *tun = (struct pico_device_tun *) dev; struct pollfd pfd; unsigned char buf[TUN_MTU]; int len; pfd.fd = tun->fd; pfd.events = POLLIN; do { if (poll(&pfd, 1, 0) <= 0) return loop_score; len = read(tun->fd, buf, TUN_MTU); if (len > 0) { loop_score--; pico_stack_recv(dev, buf, (uint32_t)len); } } while(loop_score > 0); return 0; }
static int pico_vde_poll(struct pico_device *dev, int loop_score) { struct pico_device_vde *vde = (struct pico_device_vde *) dev; struct pollfd pfd; unsigned char buf[VDE_MTU]; int len; pfd.fd = vde_datafd(vde->conn); pfd.events = POLLIN; do { if (poll(&pfd, 1, 0) <= 0) return loop_score; len = vde_recv(vde->conn, buf, VDE_MTU, 0); if (len > 0) { /* dbg("Received pkt.\n"); */ loop_score--; pico_stack_recv(dev, buf, len); } } while(loop_score > 0); return 0; }
static int pico_vde_poll(struct pico_device *dev, int loop_score) { struct pico_device_vde *vde = (struct pico_device_vde *) dev; struct pollfd pfd; unsigned char buf[VDE_MTU]; int len; pfd.fd = vde_datafd(vde->conn); pfd.events = POLLIN; do { if (poll(&pfd, 1, 0) <= 0) return loop_score; len = vde_recv(vde->conn, buf, VDE_MTU, 0); if (len > 0) { //printf("Received pkt.\n"); if ((vde->lost_in == 0) || ((pico_rand() % 100) > vde->lost_in)) { loop_score--; pico_stack_recv(dev, buf, (uint32_t)len); } } } while(loop_score > 0); return 0; }
static void pico_dev_pcap_cb(u_char *u, const struct pcap_pkthdr *h, const u_char *data) { struct pico_dev *dev = (struct pico_dev *)u; pico_stack_recv(dev, data, h->len); }
void pico_dev_netmap_cb(u_char *u, const struct nm_pkthdr *h, const uint8_t *buf) { struct pico_device *dev = (struct pico_device *) u; pico_stack_recv(dev, (uint8_t *) buf, (uint32_t) h->len); }