Add and use rs_debug() instead of fprintf to stderr.
authorLinus Nordberg <linus@nordu.net>
Fri, 4 Feb 2011 12:44:19 +0000 (13:44 +0100)
committerLinus Nordberg <linus@nordu.net>
Fri, 4 Feb 2011 12:44:19 +0000 (13:44 +0100)
lib/debug.c
lib/debug.h
lib/packet.c

index 801f2fb..485e29a 100644 (file)
@@ -21,6 +21,7 @@ rs_dump_packet (const struct rs_packet *pkt)
           p->code,
           p->id,
           p->data_len);
+  fflush (stderr);
 }
 
 void
@@ -28,3 +29,19 @@ rs_dump_attr (const struct rs_attr *attr)
 {
   vp_printlist (stderr, attr->vp);
 }
+
+#if defined DEBUG
+int
+rs_debug (const char *fmt, ...)
+{
+  int n;
+  va_list args;
+
+  va_start (args, fmt);
+  n = vfprintf (stderr, fmt, args);
+  va_end (args);
+  fflush (stderr);
+
+  return n;
+}
+#endif
index 09a6529..3156c24 100644 (file)
@@ -14,6 +14,12 @@ extern "C" {
 void rs_dump_packet (const struct rs_packet *pkt);
 void rs_dump_attr (const struct rs_attr *attr);
 
+#if defined DEBUG
+int rs_debug (const char *fmt, ...);
+#else
+#define rs_debug (void)
+#endif
+
 #if defined (__cplusplus)
 }
 #endif
index 60ac18b..19ddb9c 100644 (file)
@@ -52,11 +52,11 @@ _do_send (struct rs_packet *pkt)
                 pkt->conn->active_peer->addr->ai_addrlen,
                 host, sizeof(host), serv, sizeof(serv),
                 0 /* NI_NUMERICHOST|NI_NUMERICSERV*/);
-    fprintf (stderr, "%s: about to send this to %s:%s:\n", __func__, host,
-            serv);
+    rs_debug ("%s: about to send this to %s:%s:\n", __func__, host, serv);
     rs_dump_packet (pkt);
   }
 #endif
+
   err = bufferevent_write (pkt->conn->bev, pkt->rpkt->data,
                           pkt->rpkt->data_len);
   if (err < 0)
@@ -88,9 +88,7 @@ _event_cb (struct bufferevent *bev, short events, void *ctx)
       p->is_connected = 1;
       if (conn->callbacks.connected_cb)
        conn->callbacks.connected_cb (conn->user_data);
-#if defined (DEBUG)
-      fprintf (stderr, "%s: connected\n", __func__);
-#endif
+      rs_debug ("%s: connected\n", __func__);
       if (_do_send (pkt))
        return;
       if (conn->callbacks.sent_cb)
@@ -106,15 +104,16 @@ _event_cb (struct bufferevent *bev, short events, void *ctx)
               err;
               err = bufferevent_get_openssl_error (conn->bev))
            {
-             fprintf (stderr, "%s: openssl error: %s\n", __func__,
-                      ERR_error_string (err, NULL)); /* DEBUG, until verified that pushed errors will actually be handled  */
+             fprintf (stderr, "%s: DEBUG: openssl error: %s\n", __func__,
+                      ERR_error_string (err, NULL)); /* FIXME: DEBUG, until verified that pushed errors will actually be handled  */
              rs_err_conn_push_fl (pkt->conn, RSE_SSLERR, __FILE__, __LINE__,
                                   "%d", err);
            }
        }
 #endif /* RS_ENABLE_TLS */
+
       rs_err_conn_push_fl (pkt->conn, RSE_CONNERR, __FILE__, __LINE__, NULL);
-      fprintf (stderr, "%s: BEV_EVENT_ERROR\n", __func__); /* DEBUG, until verified that pushed errors will actually be handled  */
+      fprintf (stderr, "%s: DEBUG: BEV_EVENT_ERROR\n", __func__); /* FIXME: DEBUG, until verified that pushed errors will actually be handled  */
     }
 }
 
@@ -248,7 +247,7 @@ _evlog_cb (int severity, const char *msg)
       sevstr = "???";
       break;
     }
-  fprintf (stderr, "libevent: [%s] %s\n", sevstr, msg);
+  fprintf (stderr, "libevent: [%s] %s\n", sevstr, msg); /* FIXME: stderr?  */
 }
 
 static int