* 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 BSD sockets select() event engine.
+ * @version $Id$
*/
#include "config.h"
-#include "ircd_events.h"
-
-#include "ircd.h"
-#include "ircd_log.h"
-#include "s_debug.h"
-
/* On BSD, define FD_SETSIZE to what we want before including sys/types.h */
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
# if !defined(FD_SETSIZE)
-# define FD_SETSIZE MAXCONNECTIONS
+# define FD_SETSIZE ((MAXCONNECTIONS)+4)
# endif
#endif
-#include <assert.h>
+#include "ircd_events.h"
+
+#include "ircd.h"
+#include "ircd_log.h"
+#include "s_debug.h"
+
+/* #include <assert.h> -- Now using assert in ircd_log.h */
#include <errno.h>
#include <string.h> /* needed for bzero() on OS X */
#include <sys/socket.h>
#include <time.h>
#include <unistd.h>
-#define SELECT_ERROR_THRESHOLD 20 /* after 20 select errors, restart */
-#define ERROR_EXPIRE_TIME 3600 /* expire errors after an hour */
+#if FD_SETSIZE < (MAXCONNECTIONS + 4)
+/*
+ * Sanity check
+ *
+ * All operating systems work when MAXCONNECTIONS <= 252.
+ * Most operating systems work when MAXCONNECTIONS <= 1020 and FD_SETSIZE is
+ * updated correctly in the system headers (on BSD systems sys/types.h might
+ * have abruptly redefined it so the check is still done), you might
+ * already need to recompile your kernel.
+ * For larger FD_SETSIZE your mileage may vary (kernel patches may be needed).
+ */
+# error FD_SETSIZE is too small or MAXCONNECTIONS too large.
+#endif
+#define SELECT_ERROR_THRESHOLD 20 /**< after 20 select errors, restart */
+#define ERROR_EXPIRE_TIME 3600 /**< expire errors after an hour */
+
+/** Array of active Socket structures, indexed by file descriptor. */
static struct Socket* sockList[FD_SETSIZE];
+/** Maximum file descriptor currently used. */
static int highest_fd;
+/** Global read event interest bitmap. */
static fd_set global_read_set;
+/** Global write event interest bitmap. */
static fd_set global_write_set;
+/** Number of recent errors from select(). */
static int errors = 0;
+/** 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 select engine */
+/** Initialize the select() 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; /* initialization successful */
}
-/* Figure out what events go with a given state */
+/** Figure out what events go with a given state.
+ * @param[in] state %Socket state to consider.
+ * @param[in] events User-specified preferred event set.
+ * @return Actual set of preferred events.
+ */
static unsigned int
state_to_events(enum SocketState state, unsigned int events)
{
return 0;
}
-/* Toggle bits in the global fd sets appropriately */
+/** Set interest events in #global_read_set and #global_write_set as appropriate.
+ * @param[in] fd File descriptor to operate on.
+ * @param[in] clear Set of interest events to clear from socket.
+ * @param[in] set Set of interest events to set on socket.
+ */
static void
set_or_clear(int fd, unsigned int clear, unsigned int set)
{
}
}
-/* add a socket to be listened on */
+/** 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; /* success */
}
-/* socket switching to new state */
+/** Handle state transition for a socket.
+ * @param[in] sock Socket changing state.
+ * @param[in] new_state New state for socket.
+ */
static void
engine_state(struct Socket* sock, enum SocketState new_state)
{
state_to_events(new_state, s_events(sock))); /* new state */
}
-/* socket events changing */
+/** 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_events(struct Socket* sock, unsigned int new_events)
{
state_to_events(s_state(sock), new_events)); /* new events */
}
-/* socket going away */
+/** Remove a socket from the event engine.
+ * @param[in] sock Socket being destroyed.
+ */
static void
engine_delete(struct Socket* sock)
{
highest_fd--;
}
-/* engine event loop */
+/** Run engine event loop.
+ * @param[in] gen Lists of generators of various types.
+ */
static void
engine_loop(struct Generators* gen)
{
}
}
+/** Descriptor for select() event engine. */
struct Engine engine_select = {
"select()", /* Engine name */
engine_init, /* Engine initialization function */