--- libaitmqtt/src/srvside.c 2012/06/29 13:54:48 1.3 +++ libaitmqtt/src/srvside.c 2022/09/15 16:03:44 1.3.10.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: srvside.c,v 1.3 2012/06/29 13:54:48 misho Exp $ +* $Id: srvside.c,v 1.3.10.1 2022/09/15 16:03:44 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 +Copyright 2004 - 2022 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -50,24 +50,20 @@ SUCH DAMAGE. * mqtt_srv_cliInit() Init MQTT server side support for clients * * @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, int nb) +mqtt_srv_cliInit(int sock, u_short timeout, int nb) { mqtt_srv_t *srv = NULL; struct timeval tv = { timeout, 0 }; - int n; +#ifdef MQTT_SET_CLIBUF + int n = MQTT_SET_CLIBUF; +#endif - if (!buf || !buf->msg_base || !buf->msg_len) - return srv; - else - n = buf->msg_len; - - srv = malloc(sizeof(mqtt_srv_t)); + srv = e_malloc(sizeof(mqtt_srv_t)); if (!srv) { LOGERR; return srv; @@ -75,14 +71,15 @@ mqtt_srv_cliInit(int sock, mqtt_msg_t * __restrict buf memset(srv, 0, sizeof(mqtt_srv_t)); /* set options of client socket */ +#ifdef MQTT_SET_CLIBUF setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &n, sizeof n); setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &n, sizeof n); +#endif 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; srv->timeout = timeout; return srv; @@ -98,7 +95,7 @@ void mqtt_srv_cliFini(mqtt_srv_t ** __restrict psrv) { if (psrv && *psrv) { - free(*psrv); + e_free(*psrv); *psrv = NULL; } } @@ -116,7 +113,7 @@ mqtt_srv_cliDispatch(mqtt_srv_t * __restrict srv, int { struct mqtthdr *hdr; - if (!srv || !srv->buf->msg_base || !srv->buf->msg_len) + if (!srv || !srv->buf || !srv->buf->msg_base || !srv->buf->msg_len) return -1; if (srv->buf->msg_len < sizeof(struct mqtthdr) || rlen < sizeof(struct mqtthdr)) { mqtt_SetErr(EINVAL, "Message is too short ...");