diff th_network.c @ 103:f7bec3f7181d

Change connection creation API to specify incoming buffer size.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 21 Jun 2014 05:11:06 +0300
parents 6ca407bfbeaf
children ec5a5e573885
line wrap: on
line diff
--- a/th_network.c	Sat Jun 21 02:41:29 2014 +0300
+++ b/th_network.c	Sat Jun 21 05:11:06 2014 +0300
@@ -109,7 +109,8 @@
 
 th_conn_t * th_conn_new(
     void (*errfunc)(th_conn_t *conn, int err, const char *msg),
-    void (*msgfunc)(th_conn_t *conn, int loglevel, const char *msg))
+    void (*msgfunc)(th_conn_t *conn, int loglevel, const char *msg),
+    ssize_t bufsize)
 {
     th_conn_t *conn = th_malloc0(sizeof(th_conn_t));
 
@@ -119,6 +120,13 @@
     conn->errfunc = errfunc;
     conn->msgfunc = msgfunc;
 
+    conn->bufsize = (bufsize <= 0) ? TH_CONNBUF_SIZE : bufsize;
+    if ((conn->buf = th_malloc(conn->bufsize)) == NULL)
+    {
+        th_free(conn);
+        return NULL;
+    }
+
     return conn;
 }
 
@@ -693,7 +701,7 @@
     }
     else if (FD_ISSET(conn->socket, &tmpfds))
     {
-        conn->got_bytes = recv(conn->socket, conn->in_ptr, TH_CONNBUF_SIZE - conn->total_bytes, 0);
+        conn->got_bytes = recv(conn->socket, conn->in_ptr, conn->bufsize - conn->total_bytes, 0);
         if (conn->got_bytes < 0)
         {
             int err = th_errno_to_error(th_get_socket_errno());