ioloop-poll.c revision 68913bb7b67ce447f2d91c160b108579c7da0ba2
/*
ioloop-poll.c : I/O loop handler using poll()
Copyright (c) 2002 Timo Sirainen
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* @UNSAFE: whole file */
#include "lib.h"
#include "ioloop-internal.h"
#ifdef IOLOOP_POLL
#ifndef INITIAL_POLL_FDS
# define INITIAL_POLL_FDS 128
#endif
struct ioloop_handler_data {
unsigned int idx_size;
int *fd_index;
};
{
struct ioloop_handler_data *data;
}
{
}
{
unsigned int old_size;
int index;
/* grow the fd -> index array */
sizeof(int) * old_size,
}
/* grow the fd array */
}
/* update existing pollfd */
} else {
/* add new pollfd */
}
}
{
int index;
}
}
/* remove the whole pollfd */
return; /* removing last one */
/* move the last pollfd over the removed one */
}
}
{
unsigned int t_id;
/* get the time left for next timeout task */
i_warning("poll() : %m");
/* execute timeout handlers */
/* no I/O events */
return;
}
/* execute the I/O handlers in prioritized order */
/* we were destroyed, and io->fd points to
-1 now, so we can't know if there was any
revents left. */
continue;
}
continue;
ret--;
i_error("invalid I/O fd %d, callback %p",
continue;
}
continue;
continue;
}
i_panic("Leaked a t_pop() call!");
}
}
#endif