/* TODO: Use mini-os's blocking poll */ static void netfrontif_thread(void *argp) { struct netif *netif = argp; struct netfrontif *nfi = netif->state; struct netfront_dev *dev = nfi->dev; #ifdef CONFIG_SELECT_POLL int fd; fd_set rfds; struct timeval tv; fd = netfrontif_fd(netif); FD_ZERO(&rfds); tv.tv_sec = CONFIG_LWIP_SELECT_TIMEOUT; tv.tv_usec = 0; #endif while (likely(!nfi->_thread_exit)) { #ifdef CONFIG_SELECT_POLL FD_SET(fd, &rfds); select(fd + 1, &rfds, NULL, NULL, &tv); #else schedule(); #endif network_rx(dev); } nfi->_thread_exit = 0; }
void netfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data) { int flags; struct netfront_dev *dev = data; local_irq_save(flags); network_tx_buf_gc(dev); network_rx(dev); local_irq_restore(flags); }
ssize_t netfront_receive(struct netfront_dev *dev, unsigned char *data, size_t len) { unsigned long flags; int fd = dev->fd; ASSERT(current == main_thread); dev->rlen = 0; dev->data = data; dev->len = len; local_irq_save(flags); network_rx(dev); if (!dev->rlen && fd != -1) /* No data for us, make select stop returning */ files[fd].read = 0; /* Before re-enabling the interrupts, in case a packet just arrived in the * meanwhile. */ local_irq_restore(flags); dev->data = NULL; dev->len = 0; return dev->rlen; }