summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2011-02-04 13:44:19 +0100
committerLinus Nordberg <linus@nordu.net>2011-02-04 13:44:19 +0100
commit17a43cf2205a933169e11bc9280431577a183e65 (patch)
tree8ed8351d48576fb94ebd4088ef0dea94c614b81c
parent094640561e271d0224613c207b646488f437d8ef (diff)
Add and use rs_debug() instead of fprintf to stderr.
-rw-r--r--lib/debug.c17
-rw-r--r--lib/debug.h6
-rw-r--r--lib/packet.c17
3 files changed, 31 insertions, 9 deletions
diff --git a/lib/debug.c b/lib/debug.c
index 801f2fb..485e29a 100644
--- a/lib/debug.c
+++ b/lib/debug.c
@@ -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
diff --git a/lib/debug.h b/lib/debug.h
index 09a6529..3156c24 100644
--- a/lib/debug.h
+++ b/lib/debug.h
@@ -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
diff --git a/lib/packet.c b/lib/packet.c
index 60ac18b..19ddb9c 100644
--- a/lib/packet.c
+++ b/lib/packet.c
@@ -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