changeset 564:6e5789cbb4d4

Change network layer error/info message passing API to pass direct strings instead of fmt+ap varargs in the connection context callback functions. Also rename the callback functions in the main program.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 15 Nov 2012 20:27:44 +0200
parents c3e4e8f3c658
children de1af9652fef
files main.c network.c network.h
diffstat 3 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Thu Nov 15 20:26:10 2012 +0200
+++ b/main.c	Thu Nov 15 20:27:44 2012 +0200
@@ -383,17 +383,17 @@
 }
 
 
-void errorFunc(struct _nn_conn_t *conn, const char *fmt, va_list ap)
+void nn_network_errfunc(struct _nn_conn_t *conn, const char *msg)
 {
     (void) conn;
-    errorMsgV(fmt, ap);
+    errorMsg("%s", msg);
 }
 
 
-void messageFunc(struct _nn_conn_t *conn, const char *fmt, va_list ap)
+void nn_network_msgfunc(struct _nn_conn_t *conn, const char *msg)
 {
     (void) conn;
-    printMsgV(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap);
+    printMsgConst(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, msg);
 }
 
 
@@ -1982,7 +1982,7 @@
     }
 
     // Create a connection
-    conn = nn_conn_new(errorFunc, messageFunc);
+    conn = nn_conn_new(nn_network_errfunc, nn_network_msgfunc);
     if (conn == NULL)
     {
         errorMsg("Could not create connection structure.\n");
--- a/network.c	Thu Nov 15 20:26:10 2012 +0200
+++ b/network.c	Thu Nov 15 20:27:44 2012 +0200
@@ -70,10 +70,14 @@
 {
     if (conn->errfunc != NULL)
     {
+        char *msg;
         va_list ap;
         va_start(ap, fmt);
-        conn->errfunc(conn, fmt, ap);
+        msg = th_strdup_vprintf(fmt, ap);
         va_end(ap);
+
+        conn->errfunc(conn, msg);
+        th_free(msg);
     }
 }
 
@@ -82,10 +86,14 @@
 {
     if (conn->msgfunc != NULL)
     {
+        char *msg;
         va_list ap;
         va_start(ap, fmt);
-        conn->msgfunc(conn, fmt, ap);
+        msg = th_strdup_vprintf(fmt, ap);
         va_end(ap);
+
+        conn->msgfunc(conn, msg);
+        th_free(msg);
     }
 }
 
@@ -104,8 +112,8 @@
 
 
 nn_conn_t * nn_conn_new(
-    void (*errfunc)(nn_conn_t *conn, const char *fmt, va_list ap),
-    void (*msgfunc)(nn_conn_t *conn, const char *fmt, va_list ap))
+    void (*errfunc)(nn_conn_t *conn, const char *msg),
+    void (*msgfunc)(nn_conn_t *conn, const char *msg))
 {
     nn_conn_t *conn = th_calloc(1, sizeof(nn_conn_t));
 
--- a/network.h	Thu Nov 15 20:26:10 2012 +0200
+++ b/network.h	Thu Nov 15 20:27:44 2012 +0200
@@ -91,8 +91,8 @@
     struct in_addr addr;
     fd_set sockfds;
 
-    void (*errfunc)(struct _nn_conn_t *conn, const char *fmt, va_list ap);
-    void (*msgfunc)(struct _nn_conn_t *conn, const char *fmt, va_list ap);
+    void (*errfunc)(struct _nn_conn_t *conn, const char *msg);
+    void (*msgfunc)(struct _nn_conn_t *conn, const char *msg);
 
     int err;
     int status;
@@ -109,8 +109,8 @@
 
 struct hostent *nn_resolve_host(nn_conn_t *conn, const char *name);
 nn_conn_t * nn_conn_new(
-    void (*errfunc)(nn_conn_t *conn, const char *fmt, va_list ap),
-    void (*msgfunc)(nn_conn_t *conn, const char *fmt, va_list ap));
+    void (*errfunc)(nn_conn_t *conn, const char *msg),
+    void (*msgfunc)(nn_conn_t *conn, const char *msg));
 
 int         nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host);
 int         nn_conn_open(nn_conn_t *conn, const int port, const char *host);