Mercurial > hg > nnchat
diff network.c @ 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 | 9141f13be70c |
children | 97a49a6cc959 |
line wrap: on
line diff
--- 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));