#if HAVE_CRT #define _CRTDBG_MAP_ALLOC #include #include #endif //HAVE_CRT /* * Copyright (C) 2017, University of the Basque Country (UPV/EHU) * Contact for licensing options: * * The original file was part of Open Source Doubango Framework * Copyright (C) 2010-2011 Mamadou Diop. * Copyright (C) 2012 Doubango Telecom * * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DOUBANGO. * */ #include "tnet_poll.h" #if USE_POLL && (!HAVE_POLL || !HAVE_POLL_H) /** * * @brief poll() method implementation for multiplexing network sockets. * * @param fds An array of pollfd structures. * @param nfds The number of file descriptors set in fds[ ]. * @param timeout How long poll() should wait for an event to occur (in milliseconds). * * @return The number of elements in fdarray for which an revents member of the POLLFD structure is nonzero. * If the the returned value if <0 this mean that error occurred. **/ int tnet_poll(tnet_pollfd_t fds[ ], tnet_nfds_t nfds, int timeout) { tsk_size_t i; int ret; int highest_fd = -1; fd_set readfds; fd_set writefds; fd_set exceptfds; struct timeval timetowait; /* * cleanup fd_sets */ FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); /* * set timeout */ if(timeout >=0){ timetowait.tv_sec = (timeout/1000); timetowait.tv_usec = (timeout%1000) * 1000; } /* * add descriptors to the fd_sets */ for(i = 0; i=0) ? &timetowait : 0)) >= 0){ for(i = 0; i