Improve the clean-up of outdated IAuth instances on rehash (SF bug #2789656).
[ircu2.10.12-pk.git] / ircd / engine_devpoll.c
index 5cf7effdd6919435e2d4d04faae0b03dbd2ee0dc..9ef4dee0b36a77817243469d58d25dfc20defd8b 100644 (file)
  * 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 Solaris /dev/poll event engine.
+ * @version $Id$
  */
 #include "config.h"
 
@@ -28,7 +30,7 @@
 #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 <fcntl.h>
 #include <sys/devpoll.h>
@@ -38,8 +40,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#define DEVPOLL_ERROR_THRESHOLD        20      /* after 20 devpoll errors, restart */
-#define ERROR_EXPIRE_TIME      3600    /* expire errors after an hour */
+#define DEVPOLL_ERROR_THRESHOLD        20      /**< after 20 devpoll errors, restart */
+#define ERROR_EXPIRE_TIME      3600    /**< expire errors after an hour */
 
 /* Figure out what bits to set for read */
 #if defined(POLLMSG) && defined(POLLIN) && defined(POLLRDNORM)
 #  define POLLWRITEFLAGS POLLWRNORM
 #endif
 
+/** Array of active Socket structures, indexed by file descriptor. */
 static struct Socket** sockList;
+/** Maximum file descriptor supported, plus one. */
 static int devpoll_max;
+/** File descriptor for /dev/poll device. */
 static int devpoll_fd;
 
+/** Number of recent errors from /dev/poll. */
 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)
 {
@@ -76,7 +85,10 @@ error_clear(struct Event* ev)
     timer_del(ev_timer(ev));
 }
 
-/* initialize the devpoll engine */
+/** Initialize the /dev/poll 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)
 {
@@ -100,7 +112,11 @@ engine_init(int max_sockets)
   return 1;
 }
 
-/* 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)
 {
@@ -123,7 +139,10 @@ state_to_events(enum SocketState state, unsigned int events)
   return 0;
 }
 
-/* Reset the desired events */
+/** Set the desired events for a socket.
+ * @param[in,out] sock Socket to operate on.
+ * @param[in] events User-specified preferred event set.
+ */
 static void
 set_events(struct Socket* sock, unsigned int events)
 {
@@ -166,7 +185,10 @@ set_events(struct Socket* sock, unsigned int events)
   s_ed_int(sock) = 1; /* mark that we've added a pollfd */
 }
 
-/* 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)
 {
@@ -192,7 +214,10 @@ 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)
 {
@@ -206,7 +231,10 @@ engine_state(struct Socket* sock, enum SocketState new_state)
   set_events(sock, state_to_events(new_state, s_events(sock)));
 }
 
-/* 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)
 {
@@ -220,7 +248,9 @@ engine_events(struct Socket* sock, unsigned int new_events)
   set_events(sock, state_to_events(s_state(sock), 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)
 {
@@ -235,7 +265,9 @@ engine_delete(struct Socket* sock)
   sockList[s_fd(sock)] = 0; /* zero the socket list entry */
 }
 
-/* engine event loop */
+/** Run engine event loop.
+ * @param[in] gen Lists of generators of various types.
+ */
 static void
 engine_loop(struct Generators* gen)
 {
@@ -398,8 +430,6 @@ engine_loop(struct Generators* gen)
        break;
       }
 
-      assert(s_fd(sock) == polls[i].fd);
-
       gen_ref_dec(sock); /* we're done with it */
     }
 
@@ -407,6 +437,7 @@ engine_loop(struct Generators* gen)
   }
 }
 
+/** Descriptor for /dev/poll event engine. */
 struct Engine engine_devpoll = {
   "/dev/poll",         /* Engine name */
   engine_init,         /* Engine initialization function */