void unabto_tcp_fallback_epoll_event(struct epoll_event* event) { nabto_connect* con = (nabto_connect*)event->data.ptr; if (con->epollEventType == UNABTO_EPOLL_TYPE_TCP_FALLBACK) { if (event->events & EPOLLIN) { unabto_tcp_fallback_read_ready(con); } if (event->events & EPOLLOUT) { unabto_tcp_fallback_write_ready(con); } } }
void tunnel_loop_epoll() { struct epoll_event events[MAX_EPOLL_EVENTS]; int timeout; nabto_stamp_t ne; nabto_stamp_t now; int nfds; int i; if (!unabto_init()) { NABTO_LOG_FATAL(("Failed to initialize unabto")); } if (!init_tunnel_module()) { NABTO_LOG_FATAL(("Cannot initialize tunnel module")); return; } unabto_time_auto_update(false); // time is updated here and after the select since that's the only blocking point. unabto_time_update_stamp(); while (true) { int i; unabto_next_event(&ne); now = nabtoGetStamp(); timeout = nabtoStampDiff2ms(nabtoStampDiff(&ne, &now)); if (timeout < 0) { timeout = 0; } nfds = epoll_wait(unabto_epoll_fd, events, MAX_EPOLL_EVENTS, timeout); unabto_time_update_stamp(); for (i = 0; i < nfds; i++) { unabto_epoll_event_handler* handler = (unabto_epoll_event_handler*)events[i].data.ptr; if (handler->epollEventType == UNABTO_EPOLL_TYPE_UDP) { unabto_epoll_event_handler_udp* udpHandler = (unabto_epoll_event_handler_udp*)handler; bool status; do { status = unabto_read_socket(udpHandler->fd); } while (status); } #if NABTO_ENABLE_TCP_FALLBACK if (handler->epollEventType == UNABTO_EPOLL_TYPE_TCP_FALLBACK) { nabto_connect* con = (nabto_connect*)handler; if (events[i].events & EPOLLIN) { unabto_tcp_fallback_read_ready(con); } if (events[i].events & EPOLLOUT) { unabto_tcp_fallback_write_ready(con); } } #endif if (handler->epollEventType == UNABTO_EPOLL_TYPE_TCP_TUNNEL) { tunnel* tunnelPtr = (tunnel*)handler; if (tunnelPtr->sock != INVALID_SOCKET) { tunnel_event(tunnelPtr, TUNNEL_EVENT_SOURCE_TCP_READ); } if (tunnelPtr->sock != INVALID_SOCKET) { tunnel_event(tunnelPtr, TUNNEL_EVENT_SOURCE_TCP_WRITE); } } } unabto_time_event(); } deinit_tunnel_module(); unabto_close(); }