Diff for /mqtt/src/daemon.c between versions 1.1.2.4 and 1.1.2.5

version 1.1.2.4, 2011/12/01 08:15:25 version 1.1.2.5, 2011/12/01 08:45:01
Line 1 Line 1
 #include "global.h"  #include "global.h"
   
   
static intstatic void *
startSession(int s, const char *csAddr)startSession(sched_task_t *task)
 {  {
           close(TASK_FD(task));
           VERB(1) syslog(LOG_DEBUG, "Close client %s with socket=%d", 
                           (char*) TASK_ARG(task), (int) TASK_FD(task));
           if (TASK_ARG(task))
                   free(TASK_ARG(task));
         return 0;          return 0;
 }  }
   
 /* ----------------------------------------------------------------------- */  /* ----------------------------------------------------------------------- */
   
   static void *
   thrSched(void *arg __unused)
   {
           FTRACE(1);
   
           schedRun(root, (intptr_t*) &Kill);
           pthread_exit(NULL);
   }
   
 int  int
 Run(int sock)  Run(int sock)
 {  {
         io_sockaddr_t sa;          io_sockaddr_t sa;
         socklen_t sslen = sizeof sa.ss;          socklen_t sslen = sizeof sa.ss;
         int cli;          int cli;
        char szAddr[STRSIZ] = { 0 };        char *str = NULL, szAddr[STRSIZ] = { 0 };
         pthread_t tid;
   
         FTRACE(1);          FTRACE(1);
   
           if (pthread_create(&tid, NULL, thrSched, NULL)) {
                   syslog(LOG_ERR, "Error:: thread scheduler #%d - %s", errno, strerror(errno));
                   return -1;
           } else
                   pthread_detach(tid);
           VERB(2) syslog(LOG_DEBUG, "Run scheduler management thread");
   
         if (listen(sock, SOMAXCONN) == -1) {          if (listen(sock, SOMAXCONN) == -1) {
                 syslog(LOG_ERR, "Error:: listen(%d) #%d - %s\n", sock, errno, strerror(errno));                  syslog(LOG_ERR, "Error:: listen(%d) #%d - %s\n", sock, errno, strerror(errno));
                   pthread_cancel(tid);
                 return -1;                  return -1;
         }          }
   
Line 50  Run(int sock) Line 73  Run(int sock)
                                                                 sa.sa.sa_family);                                                                  sa.sa.sa_family);
                                                 continue;                                                  continue;
                                 }                                  }
                                syslog(LOG_DEBUG, "Connected client with socket=%d from %s", cli, szAddr);                                str = strdup(szAddr);
                                 syslog(LOG_DEBUG, "Connected client with socket=%d from %s", cli, str);
                         }                          }
   
                if (startSession(cli, szAddr)) {                if (!schedRead(root, startSession, str, cli)) {
                         close(cli);                          close(cli);
                         VERB(1) syslog(LOG_DEBUG, "Terminated client with socket=%d", cli);                          VERB(1) syslog(LOG_DEBUG, "Terminated client with socket=%d", cli);
                        continue;                        if (str)
                                 free(str);
                 }                  }
         }          }
   

Removed from v.1.1.2.4  
changed lines
  Added in v.1.1.2.5


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