Diff for /libaitmqtt/src/srvside.c between versions 1.3 and 1.3.10.1

version 1.3, 2012/06/29 13:54:48 version 1.3.10.1, 2022/09/15 16:03:44
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012Copyright 2004 - 2022
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 50  SUCH DAMAGE. Line 50  SUCH DAMAGE.
  * mqtt_srv_cliInit() Init MQTT server side support for clients   * mqtt_srv_cliInit() Init MQTT server side support for clients
  *   *
  * @sock = Client socket from accept()   * @sock = Client socket from accept()
  * @buf = Message buffer  
  * @timeout = timeout   * @timeout = timeout
  * @nb = Non block socket   * @nb = Non block socket
  * return: NULL error or !=NULL allocated server handle   * return: NULL error or !=NULL allocated server handle
  */   */
 mqtt_srv_t *  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;          mqtt_srv_t *srv = NULL;
         struct timeval tv = { timeout, 0 };          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)        srv = e_malloc(sizeof(mqtt_srv_t));
                return srv; 
        else 
                n = buf->msg_len; 
 
        srv = malloc(sizeof(mqtt_srv_t)); 
         if (!srv) {          if (!srv) {
                 LOGERR;                  LOGERR;
                 return srv;                  return srv;
Line 75  mqtt_srv_cliInit(int sock, mqtt_msg_t * __restrict buf Line 71  mqtt_srv_cliInit(int sock, mqtt_msg_t * __restrict buf
                 memset(srv, 0, sizeof(mqtt_srv_t));                  memset(srv, 0, sizeof(mqtt_srv_t));
   
         /* set options of client socket */          /* set options of client socket */
   #ifdef MQTT_SET_CLIBUF
         setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &n, sizeof n);          setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &n, sizeof n);
         setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &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_SNDTIMEO, &tv, sizeof tv);
         setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);          setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
         ioctl(sock, FIONBIO, nb);          ioctl(sock, FIONBIO, nb);
   
         srv->sock = sock;          srv->sock = sock;
         srv->buf = buf;  
         srv->timeout = timeout;          srv->timeout = timeout;
   
         return srv;          return srv;
Line 98  void Line 95  void
 mqtt_srv_cliFini(mqtt_srv_t ** __restrict psrv)  mqtt_srv_cliFini(mqtt_srv_t ** __restrict psrv)
 {  {
         if (psrv && *psrv) {          if (psrv && *psrv) {
                free(*psrv);                e_free(*psrv);
                 *psrv = NULL;                  *psrv = NULL;
         }          }
 }  }
Line 116  mqtt_srv_cliDispatch(mqtt_srv_t * __restrict srv, int  Line 113  mqtt_srv_cliDispatch(mqtt_srv_t * __restrict srv, int 
 {  {
         struct mqtthdr *hdr;          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;                  return -1;
         if (srv->buf->msg_len < sizeof(struct mqtthdr) || rlen < sizeof(struct mqtthdr)) {          if (srv->buf->msg_len < sizeof(struct mqtthdr) || rlen < sizeof(struct mqtthdr)) {
                 mqtt_SetErr(EINVAL, "Message is too short ...");                  mqtt_SetErr(EINVAL, "Message is too short ...");

Removed from v.1.3  
changed lines
  Added in v.1.3.10.1


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>