ioloop-select.c revision ccb7e5fbb0ab17e75f370bf08c0a7ff9613c6014
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ioloop-select.c : I/O loop handler using select()
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen Copyright (c) 2002 Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen Permission is hereby granted, free of charge, to any person obtaining
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen a copy of this software and associated documentation files (the
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "Software"), to deal in the Software without restriction, including
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen without limitation the rights to use, copy, modify, merge, publish,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen distribute, sublicense, and/or sell copies of the Software, and to
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen permit persons to whom the Software is furnished to do so, subject to
bcf5af3335a814e4923ba1bf2e0d80eb6dabfb22Timo Sirainen the following conditions:
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen The above copyright notice and this permission notice shall be
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen included in all copies or substantial portions of the Software.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
bcf5af3335a814e4923ba1bf2e0d80eb6dabfb22Timo Sirainen IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
5a58037ad75b88356d82240fab2bc604de03107eTimo Sirainen TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
659fe5d24825b160cae512538088020d97a60239Timo Sirainen# include <sys/select.h> /* According to POSIX 1003.1-2001 */
659fe5d24825b160cae512538088020d97a60239Timo Sirainen ioloop->handler_data = p_new(ioloop->pool, IOLoopHandlerData, 1);
659fe5d24825b160cae512538088020d97a60239Timo Sirainenvoid io_loop_handle_add(IOLoop ioloop, int fd, int condition)
659fe5d24825b160cae512538088020d97a60239Timo Sirainenvoid io_loop_handle_remove(IOLoop ioloop, int fd, int condition)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen unsigned int t_id;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* get the time left for next timeout task */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen io_loop_get_wait_time(ioloop->timeouts, &tv, NULL);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen memcpy(&tmp_read_fds, &ioloop->handler_data->read_fds, sizeof(fd_set));
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen memcpy(&tmp_write_fds, &ioloop->handler_data->write_fds,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ret = select(ioloop->highest_fd + 1, &tmp_read_fds, &tmp_write_fds,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* execute timeout handlers */
bcf5af3335a814e4923ba1bf2e0d80eb6dabfb22Timo Sirainen /* no I/O events */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* execute the I/O handlers in prioritized order */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen for (io = ioloop->ios; io != NULL && ret > 0; io = next) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* we were destroyed, and io->fd points to -1 now. */