Convert connection byte counters to 64-bit integers.
authorMichael Poole <mdpoole@troilus.org>
Sun, 7 Nov 2004 20:57:50 +0000 (20:57 +0000)
committerMichael Poole <mdpoole@troilus.org>
Sun, 7 Nov 2004 20:57:50 +0000 (20:57 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1263 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
acinclude.m4
configure.in
include/client.h
include/s_misc.h
ircd/ircd_snprintf.c
ircd/packet.c
ircd/s_bsd.c
ircd/s_misc.c
ircd/s_stats.c

index 5df016b479d368069f3db0094d960623a247a2de..4c477827d43cef10a1600e4a00ea7c48bd9e8efe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2004-11-07  Michael Poole <mdpoole@troilus.org>
+
+       * acinclude.m4: Look for a 64-bit integer type.
+
+       * configure.in: Look for inttypes.h, since some systems have that
+       but not stdint.h (and define 64-bit integers therein).
+
+       * include/client.h: Delete con_sendK, con_receiveK.  Make
+       con_sendB and con_receiveB 64 bits wide.
+
+       * include/s_misc.h: Delete is_cks, is_ckr, is_sks, is_skr.
+       Convert the other byte counters and the connected time counters to
+       64 bits wide.
+
+       * ircd/ircd_snprintf.c (doprintf): Unconditionalize the
+       HAVE_LONG_LONG bits, and use the 64-bit integer types from above.
+
+       * ircd/packet.c (update_bytes_received): Remove use of
+       cli_receiveK().
+
+       * ircd/s_bsd.c (deliver_it): Likewise.
+       (close_connection): Likewise.
+
+       * ircd/s_misc.c (tstats): Likewise.  Update format strings to use
+       %Lu for 64-bit integer parameters.
+
+       * ircd/s_stats (stats_links): Convert cli_sendK() and
+       cli_receiveK() use shifted versions of the byte counters, and
+       update format strings to use %Lu for 64-bit integer parameters.
+
 2004-11-07  Michael Poole <mdpoole@troilus.org>
 
        * include/s_user.h (add_silence): Delete.
index 9ad93d1c07976534da19c95ebf2374f0b4eccbb5..5a6440e26249ab15a1bd26fec1337c1f5ca96a08 100644 (file)
@@ -138,6 +138,8 @@ AC_CHECK_SIZEOF(short)
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
 AC_CHECK_SIZEOF(void *)
+AC_CHECK_SIZEOF(int64_t)
+AC_CHECK_SIZEOF(long long)
 if test "$ac_cv_sizeof_int" = 2 ; then
   AC_CHECK_TYPE(int16_t, int)
   AC_CHECK_TYPE(uint16_t, unsigned int)
@@ -158,6 +160,15 @@ elif test "$ac_cv_sizeof_long" = 4 ; then
   AC_CHECK_TYPE(uint32_t, unsigned long)
 else
   AC_MSG_ERROR([Cannot find a type with size of 32 bits])
+fi
+if test "$ac_cv_sizeof_int64_t" = 8 ; then
+  AC_CHECK_TYPE(int64_t)
+  AC_CHECK_TYPE(uint64_t)
+elif test "$ac_cv_sizeof_long_long" = 8 ; then
+  AC_CHECK_TYPE(int64_t, long long)
+  AC_CHECK_TYPE(uint64_t, unsigned long long)
+else
+  AC_MSG_ERROR([Cannot find a type with size of 64 bits])
 fi])
 
 dnl Written by John Hawkinson <jhawk@mit.edu>. This code is in the Public
index 9ed97eda297708e5fde34b9c0d5fb95b53535e82..4d3450efdbe6df52c109c934508be0c45df93860 100644 (file)
@@ -108,7 +108,7 @@ AC_LIBRARY_NET
 
 dnl Checks for header files.
 AC_HEADER_STDC
-AC_CHECK_HEADERS(crypt.h poll.h stdint.h sys/devpoll.h sys/epoll.h sys/event.h sys/param.h sys/socket.h)
+AC_CHECK_HEADERS(crypt.h poll.h inttypes.h stdint.h sys/devpoll.h sys/epoll.h sys/event.h sys/param.h sys/socket.h)
 
 dnl Checks for typedefs, structures, and compiler characteristics
 dnl AC_C_CONST
index 7a15904f46de9e1c15450a78c18e5bc57b745a3b..d0ee1273cebebfe6ef6bb71dc53243493794ab9d 100644 (file)
@@ -198,11 +198,9 @@ struct Connection
   struct MsgQ         con_sendQ;     /**< Outgoing message queue */
   struct DBuf         con_recvQ;     /**< Incoming data yet to be parsed */
   unsigned int        con_sendM;     /**< Stats: protocol messages sent */
-  unsigned int        con_sendK;     /**< Stats: total k-bytes sent */
   unsigned int        con_receiveM;  /**< Stats: protocol messages received */
-  unsigned int        con_receiveK;  /**< Stats: total k-bytes received */
-  unsigned short      con_sendB;     /**< Bytes sent, mod 1024. */
-  unsigned short      con_receiveB;  /**< Bytes received, mod 1024. */
+  uint64_t            con_sendB;     /**< Bytes sent. */
+  uint64_t            con_receiveB;  /**< Bytes received. */
   struct Listener*    con_listener;  /**< Listening socket which we accepted
                                         from. */
   struct SLink*       con_confs;     /**< Associated configuration records. */
@@ -337,12 +335,8 @@ struct Client {
 #define cli_recvQ(cli)         con_recvQ(cli_connect(cli))
 /** Get count of messages sent to client. */
 #define cli_sendM(cli)         con_sendM(cli_connect(cli))
-/** Get number of kilobytes sent to client. */
-#define cli_sendK(cli)         con_sendK(cli_connect(cli))
 /** Get number of messages received from client. */
 #define cli_receiveM(cli)      con_receiveM(cli_connect(cli))
-/** Get number of kilobytes received from client. */
-#define cli_receiveK(cli)      con_receiveK(cli_connect(cli))
 /** Get number of bytes (modulo 1024) sent to client. */
 #define cli_sendB(cli)         con_sendB(cli_connect(cli))
 /** Get number of bytes (modulo 1024) received from client. */
@@ -422,12 +416,8 @@ struct Client {
 #define con_recvQ(con)         ((con)->con_recvQ)
 /** Get number of messages sent to connection. */
 #define con_sendM(con)         ((con)->con_sendM)
-/** Get number of kilobytes sent to connection. */
-#define con_sendK(con)         ((con)->con_sendK)
 /** Get number of messages received from connection. */
 #define con_receiveM(con)      ((con)->con_receiveM)
-/** Get number of kilobytes received from connection. */
-#define con_receiveK(con)      ((con)->con_receiveK)
 /** Get number of bytes (modulo 1024) sent to connection. */
 #define con_sendB(con)         ((con)->con_sendB)
 /** Get number of bytes (modulo 1024) received from connection. */
index dbf61c297c91553197b185791c139ff682059886..2f8bc140d55e57434f9c9d4a67c200b6908f00c0 100644 (file)
@@ -30,21 +30,31 @@ struct ConfItem;
  * Structures
  */
 
+#ifdef HAVE_INTTYPES_H
+# ifndef INCLUDED_inttypes_h
+#  include <inttypes.h>
+#  define INCLUDED_inttypes_h
+# endif
+#else
+# ifdef HAVE_STDINT_H
+#  ifndef INCLUDED_stdint_h
+#   include <stdint.h>
+#   define INCLUDED_stdint_h
+#  endif
+# endif
+#endif
+
 /** Structure used to count many server-wide statistics. */
 struct ServerStatistics {
   unsigned int is_cl;           /**< number of client connections */
   unsigned int is_sv;           /**< number of server connections */
   unsigned int is_ni;           /**< connection but no idea who it was */
-  unsigned short int is_cbs;    /**< bytes sent to clients */
-  unsigned short int is_cbr;    /**< bytes received to clients */
-  unsigned short int is_sbs;    /**< bytes sent to servers */
-  unsigned short int is_sbr;    /**< bytes received to servers */
-  unsigned int is_cks;          /**< k-bytes sent to clients */
-  unsigned int is_ckr;          /**< k-bytes received to clients */
-  unsigned int is_sks;          /**< k-bytes sent to servers */
-  unsigned int is_skr;          /**< k-bytes received to servers */
-  time_t is_cti;                /**< time spent connected by clients */
-  time_t is_sti;                /**< time spent connected by servers */
+  uint64_t is_cbs;              /**< bytes sent to clients */
+  uint64_t is_cbr;              /**< bytes received to clients */
+  uint64_t is_sbs;              /**< bytes sent to servers */
+  uint64_t is_sbr;              /**< bytes received to servers */
+  uint64_t is_cti;              /**< time spent connected by clients */
+  uint64_t is_sti;              /**< time spent connected by servers */
   unsigned int is_ac;           /**< connections accepted */
   unsigned int is_ref;          /**< accepts refused */
   unsigned int is_unco;         /**< unknown commands */
index 91a9f082283648467c7f76c7a769d604081bb0d4..3c7cfb02f58792883a18b9d41c566428b2308442 100644 (file)
@@ -1742,10 +1742,8 @@ doprintf(struct Client *dest, struct BufData *buf_p, const char *fmt,
          *((char *)va_arg(vp, int *)) = TOTAL(buf_p);
        else if (fld_s.flags & TYPE_SHORT) /* eg, %hn */
          *((short *)va_arg(vp, int *)) = TOTAL(buf_p);
-#ifdef HAVE_LONG_LONG
        else if (fld_s.flags & TYPE_QUAD) /* eg, %qn */
-         *((my_quad_t *)va_arg(vp, my_quad_t *)) = TOTAL(buf_p);
-#endif /* HAVE_LONG_LONG */
+         *((int64_t *)va_arg(vp, int64_t *)) = TOTAL(buf_p);
        else if (fld_s.flags & TYPE_LONG) /* eg, %ln */
          *((long *)va_arg(vp, long *)) = TOTAL(buf_p);
        else if (fld_s.flags & TYPE_INTMAX) /* eg, %jn */
@@ -1807,10 +1805,8 @@ doprintf(struct Client *dest, struct BufData *buf_p, const char *fmt,
          fld_s.value.v_int = (unsigned char)va_arg(vp, unsigned int);
        else if (fld_s.flags & TYPE_SHORT) /* eg, %hu */
          fld_s.value.v_int = (short)va_arg(vp, unsigned int);
-#ifdef HAVE_LONG_LONG
        else if (fld_s.flags & TYPE_QUAD) /* eg, %qu */
-         fld_s.value.v_int = va_arg(vp, _large_t);
-#endif
+         fld_s.value.v_int = va_arg(vp, uint64_t);
        else if (fld_s.flags & TYPE_LONG) /* eg, %lu */
          fld_s.value.v_int = va_arg(vp, unsigned long);
        else if (fld_s.flags & TYPE_INTMAX) /* eg, %ju */
@@ -1832,10 +1828,8 @@ doprintf(struct Client *dest, struct BufData *buf_p, const char *fmt,
          signed_int = (char)va_arg(vp, unsigned int);
        else if (fld_s.flags & TYPE_SHORT) /* eg, %hd */
          signed_int = (short)va_arg(vp, unsigned int);
-#ifdef HAVE_LONG_LONG
        else if (fld_s.flags & TYPE_QUAD) /* eg, %qd */
-         signed_int = va_arg(vp, _large_t);
-#endif
+         signed_int = va_arg(vp, int64_t);
        else if (fld_s.flags & TYPE_LONG) /* eg, %ld */
          signed_int = va_arg(vp, long);
        else if (fld_s.flags & TYPE_INTMAX) /* eg, %jd */
index 100f592f0b57225c7332329bc4ebb83a60987227..87853f6922669539f9b5193f4b9834055e1d37c4 100644 (file)
@@ -42,15 +42,6 @@ static void update_bytes_received(struct Client* cptr, unsigned int length)
 {
   cli_receiveB(&me)  += length;     /* Update bytes received */
   cli_receiveB(cptr) += length;
-
-  if (cli_receiveB(cptr) > 1023) {
-    cli_receiveK(cptr) += (cli_receiveB(cptr) >> 10);
-    cli_receiveB(cptr) &= 0x03ff;   /* 2^10 = 1024, 3ff = 1023 */
-  }
-  if (cli_receiveB(&me) > 1023) {
-    cli_receiveK(&me) += (cli_receiveB(&me) >> 10);
-    cli_receiveB(&me) &= 0x03ff;
-  }
 }
 
 /** Add one message to a client's received statistics.
index 8628cbccd084f2d4249ba9e9731bafc1f3cd534a..6a3d9e4619a27afd93b1e71649d1a879091c9b6c 100644 (file)
@@ -297,18 +297,7 @@ unsigned int deliver_it(struct Client *cptr, struct MsgQ *buf)
 
     cli_sendB(cptr) += bytes_written;
     cli_sendB(&me)  += bytes_written;
-    if (cli_sendB(cptr) > 1023) {
-      cli_sendK(cptr) += (cli_sendB(cptr) >> 10);
-      cli_sendB(cptr) &= 0x03ff;    /* 2^10 = 1024, 3ff = 1023 */
-    }
-    if (cli_sendB(&me) > 1023) {
-      cli_sendK(&me) += (cli_sendB(&me) >> 10);
-      cli_sendB(&me) &= 0x03ff;
-    }
-    /*
-     * XXX - hrmm.. set blocked here? the socket didn't
-     * say it was blocked
-     */
+    /* A partial write implies that future writes will block. */
     if (bytes_written < bytes_count)
       SetFlag(cptr, FLAG_BLOCKED);
     break;
@@ -415,17 +404,7 @@ void close_connection(struct Client *cptr)
     ServerStats->is_sv++;
     ServerStats->is_sbs += cli_sendB(cptr);
     ServerStats->is_sbr += cli_receiveB(cptr);
-    ServerStats->is_sks += cli_sendK(cptr);
-    ServerStats->is_skr += cli_receiveK(cptr);
     ServerStats->is_sti += CurrentTime - cli_firsttime(cptr);
-    if (ServerStats->is_sbs > 1023) {
-      ServerStats->is_sks += (ServerStats->is_sbs >> 10);
-      ServerStats->is_sbs &= 0x3ff;
-    }
-    if (ServerStats->is_sbr > 1023) {
-      ServerStats->is_skr += (ServerStats->is_sbr >> 10);
-      ServerStats->is_sbr &= 0x3ff;
-    }
     /*
      * If the connection has been up for a long amount of time, schedule
      * a 'quick' reconnect, else reset the next-connect cycle.
@@ -449,17 +428,7 @@ void close_connection(struct Client *cptr)
     ServerStats->is_cl++;
     ServerStats->is_cbs += cli_sendB(cptr);
     ServerStats->is_cbr += cli_receiveB(cptr);
-    ServerStats->is_cks += cli_sendK(cptr);
-    ServerStats->is_ckr += cli_receiveK(cptr);
     ServerStats->is_cti += CurrentTime - cli_firsttime(cptr);
-    if (ServerStats->is_cbs > 1023) {
-      ServerStats->is_cks += (ServerStats->is_cbs >> 10);
-      ServerStats->is_cbs &= 0x3ff;
-    }
-    if (ServerStats->is_cbr > 1023) {
-      ServerStats->is_ckr += (ServerStats->is_cbr >> 10);
-      ServerStats->is_cbr &= 0x3ff;
-    }
   }
   else
     ServerStats->is_ni++;
index cdf6250275db6852b0b3a7c3f8959906b0d2f5ea..1b892fc287169dba7277fa24d1b452289a21b232 100644 (file)
@@ -583,39 +583,15 @@ void tstats(struct Client *cptr, const struct StatDesc *sd, char *param)
     {
       sp->is_sbs += cli_sendB(acptr);
       sp->is_sbr += cli_receiveB(acptr);
-      sp->is_sks += cli_sendK(acptr);
-      sp->is_skr += cli_receiveK(acptr);
       sp->is_sti += CurrentTime - cli_firsttime(acptr);
       sp->is_sv++;
-      if (sp->is_sbs > 1023)
-      {
-        sp->is_sks += (sp->is_sbs >> 10);
-        sp->is_sbs &= 0x3ff;
-      }
-      if (sp->is_sbr > 1023)
-      {
-        sp->is_skr += (sp->is_sbr >> 10);
-        sp->is_sbr &= 0x3ff;
-      }
     }
     else if (IsUser(acptr))
     {
       sp->is_cbs += cli_sendB(acptr);
       sp->is_cbr += cli_receiveB(acptr);
-      sp->is_cks += cli_sendK(acptr);
-      sp->is_ckr += cli_receiveK(acptr);
       sp->is_cti += CurrentTime - cli_firsttime(acptr);
       sp->is_cl++;
-      if (sp->is_cbs > 1023)
-      {
-        sp->is_cks += (sp->is_cbs >> 10);
-        sp->is_cbs &= 0x3ff;
-      }
-      if (sp->is_cbr > 1023)
-      {
-        sp->is_ckr += (sp->is_cbr >> 10);
-        sp->is_cbr &= 0x3ff;
-      }
     }
     else if (IsUnknown(acptr))
       sp->is_ni++;
@@ -638,10 +614,10 @@ void tstats(struct Client *cptr, const struct StatDesc *sd, char *param)
   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Client server");
   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":connected %u %u",
             sp->is_cl, sp->is_sv);
-  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes sent %u.%uK %u.%uK",
-            sp->is_cks, sp->is_cbs, sp->is_sks, sp->is_sbs);
-  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes recv %u.%uK %u.%uK",
-            sp->is_ckr, sp->is_cbr, sp->is_skr, sp->is_sbr);
-  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":time connected %Tu %Tu",
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes sent %Lu %Lu",
+            sp->is_cbs, sp->is_sbs);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes recv %Lu %Lu",
+            sp->is_cbr, sp->is_sbr);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":time connected %Lu %Lu",
             sp->is_cti, sp->is_sti);
 }
index 84b804bfef37d85d4732799a30b13a885c8ef008..1b332af99b78b708b09e39a314cd4a0acc904200 100644 (file)
@@ -289,11 +289,11 @@ stats_links(struct Client* sptr, const struct StatDesc* sd, char* name)
       if (!(!name || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
         continue;
       send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
-                 "%s %u %u %u %u %u :%Tu",
+                 "%s %u %u %Lu %u %Lu :%Tu",
                  (*(cli_name(acptr))) ? cli_name(acptr) : "<unregistered>",
                  (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
-                 (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
-                 (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
+                 (cli_sendB(acptr) >> 10), (int)cli_receiveM(acptr),
+                 (cli_receiveB(acptr) >> 10), CurrentTime - cli_firsttime(acptr));
     }
 }