* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
+ */
+/** @file
+ * @brief Linux epoll_*() event engine.
+ * @version $Id$
*/
#include "config.h"
#include "ircd_log.h"
#include "s_debug.h"
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
#include <errno.h>
#include <sys/types.h>
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h> /* bah */
+#ifdef HAVE_STDINT_H
+#include <stdint.h> /* bah */
#endif
#include <string.h>
#include <sys/epoll.h>
#endif /* epoll_create defined as stub */
-#define EPOLL_ERROR_THRESHOLD 20 /* after 20 epoll errors, restart */
-#define ERROR_EXPIRE_TIME 3600 /* expire errors after an hour */
+#define EPOLL_ERROR_THRESHOLD 20 /**< after 20 epoll errors, restart */
+#define ERROR_EXPIRE_TIME 3600 /**< expire errors after an hour */
+/** File descriptor for epoll pseudo-file. */
static int epoll_fd;
+/** Number of recent epoll errors. */
static int errors;
+/** Periodic timer to forget errors. */
static struct Timer clear_error;
-/* decrements the error count once per hour */
+/** Decrement the error count (once per hour).
+ * @param[in] ev Expired timer event (ignored).
+ */
static void
error_clear(struct Event *ev)
{
timer_del(ev_timer(ev));
}
-/* initialize the epoll engine */
+/** Initialize the epoll engine.
+ * @param[in] max_sockets Maximum number of file descriptors to support.
+ * @return Non-zero on success, or zero on failure.
+ */
static int
engine_init(int max_sockets)
{
return 1;
}
+/** Set events for a particular socket.
+ * @param[in] sock Socket to calculate events for.
+ * @param[in] state Current socket state.
+ * @param[in] events User-specified event interest list.
+ * @param[out] evt epoll event structure for socket.
+ */
static void
set_events(struct Socket *sock, enum SocketState state, unsigned int events, struct epoll_event *evt)
{
}
}
+/** Add a socket to the event engine.
+ * @param[in] sock Socket to add to engine.
+ * @return Non-zero on success, or zero on error.
+ */
static int
engine_add(struct Socket *sock)
{
return 1;
}
+/** Handle state transition for a socket.
+ * @param[in] sock Socket changing state.
+ * @param[in] new_state New state for socket.
+ */
static void
engine_set_state(struct Socket *sock, enum SocketState new_state)
{
event_generate(ET_ERROR, sock, errno);
}
+/** Handle change to preferred socket events.
+ * @param[in] sock Socket getting new interest list.
+ * @param[in] new_events New set of interesting events for socket.
+ */
static void
engine_set_events(struct Socket *sock, unsigned new_events)
{
event_generate(ET_ERROR, sock, errno);
}
+/** Remove a socket from the event engine.
+ * @param[in] sock Socket being destroyed.
+ */
static void
engine_delete(struct Socket *sock)
{
- struct epoll_event evt;
-
assert(0 != sock);
- memset(&evt, 0, sizeof(evt));
Debug((DEBUG_ENGINE, "epoll: Deleting socket %d [%p], state %s",
s_fd(sock), sock, state_to_name(s_state(sock))));
- if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, s_fd(sock), &evt) < 0)
- log_write(LS_SOCKET, L_WARNING, 0,
- "Unable to delete epoll item for socket %d", s_fd(sock));
+ /* No action necessary; epoll removes the socket on close(). */
}
+/** Run engine event loop.
+ * @param[in] gen Lists of generators of various types.
+ */
static void
engine_loop(struct Generators *gen)
{
struct epoll_event *events;
struct Socket *sock;
- size_t codesize;
+ socklen_t codesize;
int events_count, i, wait, nevs, errcode;
if ((events_count = feature_int(FEAT_POLLS_PER_LOOP)) < 20)
}
wait = timer_next(gen) ? (timer_next(gen) - CurrentTime) * 1000 : -1;
- Debug((DEBUG_INFO, "epoll: delay: %d (%d) %d", timer_next(gen),
+ Debug((DEBUG_ENGINE, "epoll: delay: %d (%d) %d", timer_next(gen),
CurrentTime, wait));
nevs = epoll_wait(epoll_fd, events, events_count, wait);
CurrentTime = time(0);
}
timer_run();
}
+ MyFree(events);
}
+/** Descriptor for dpoll event engine. */
struct Engine engine_epoll = {
"epoll()",
engine_init,