--- libaitmqtt/src/srvside.c 2012/06/29 08:22:50 1.2.4.1 +++ libaitmqtt/src/srvside.c 2012/06/29 08:44:34 1.2.4.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: srvside.c,v 1.2.4.1 2012/06/29 08:22:50 misho Exp $ +* $Id: srvside.c,v 1.2.4.2 2012/06/29 08:44:34 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -52,15 +52,20 @@ SUCH DAMAGE. * @sock = Client socket from accept() * @buf = Message buffer * @timeout = timeout + * @nb = Non block socket * return: NULL error or !=NULL allocated server handle */ mqtt_srv_t * -mqtt_srv_cliInit(int sock, mqtt_msg_t * __restrict buf, u_short timeout) +mqtt_srv_cliInit(int sock, mqtt_msg_t * __restrict buf, u_short timeout, int nb) { mqtt_srv_t *srv = NULL; + struct timeval tv = { timeout, 0 }; + int n; if (!buf || !buf->msg_base || !buf->msg_len) return srv; + else + n = buf->msg_len; srv = malloc(sizeof(mqtt_srv_t)); if (!srv) { @@ -68,6 +73,13 @@ mqtt_srv_cliInit(int sock, mqtt_msg_t * __restrict buf return srv; } else memset(srv, 0, sizeof(mqtt_srv_t)); + + /* set options of client socket */ + setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &n, sizeof n); + setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &n, sizeof n); + setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv); + setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv); + ioctl(sock, FIONBIO, nb); srv->sock = sock; srv->buf = buf;