Annotation of mqtt/src/daemon.c, revision 1.1.2.4

1.1.2.1   misho       1: #include "global.h"
                      2: 
                      3: 
1.1.2.4 ! misho       4: static int
        !             5: startSession(int s, const char *csAddr)
        !             6: {
        !             7:        return 0;
        !             8: }
        !             9: 
        !            10: /* ----------------------------------------------------------------------- */
        !            11: 
1.1.2.2   misho      12: int
1.1.2.3   misho      13: Run(int sock)
1.1.2.2   misho      14: {
1.1.2.4 ! misho      15:        io_sockaddr_t sa;
        !            16:        socklen_t sslen = sizeof sa.ss;
        !            17:        int cli;
        !            18:        char szAddr[STRSIZ] = { 0 };
        !            19: 
1.1.2.2   misho      20:        FTRACE(1);
                     21: 
1.1.2.3   misho      22:        if (listen(sock, SOMAXCONN) == -1) {
1.1.2.4 ! misho      23:                syslog(LOG_ERR, "Error:: listen(%d) #%d - %s\n", sock, errno, strerror(errno));
1.1.2.3   misho      24:                return -1;
                     25:        }
                     26: 
1.1.2.4 ! misho      27:        while (!Kill) {
        !            28:                if ((cli = accept(sock, &sa.sa, &sslen)) == -1) {
        !            29:                        syslog(LOG_ERR, "Error:: accept() #%d - %s", errno, strerror(errno));
        !            30:                        continue;
        !            31:                } else
        !            32:                        VERB(1) {
        !            33:                                switch (sa.sa.sa_family) {
        !            34:                                        case AF_INET:
        !            35:                                                inet_ntop(AF_INET, &sa.sin.sin_addr, szAddr, sslen);
        !            36:                                                snprintf(szAddr, sizeof szAddr, "%s:%d", 
        !            37:                                                                szAddr, ntohs(sa.sin.sin_port));
        !            38:                                                break;
        !            39:                                        case AF_INET6:
        !            40:                                                inet_ntop(AF_INET6, &sa.sin6.sin6_addr, szAddr, sslen);
        !            41:                                                snprintf(szAddr, sizeof szAddr, "%s:%d", 
        !            42:                                                                szAddr, ntohs(sa.sin6.sin6_port));
        !            43:                                                break;
        !            44:                                        case AF_LOCAL:
        !            45:                                                strlcpy(szAddr, sa.sun.sun_path, sizeof szAddr);
        !            46:                                                break;
        !            47:                                        default:
        !            48:                                                close(cli);
        !            49:                                                syslog(LOG_ERR, "Error:: unsupported address type %d", 
        !            50:                                                                sa.sa.sa_family);
        !            51:                                                continue;
        !            52:                                }
        !            53:                                syslog(LOG_DEBUG, "Connected client with socket=%d from %s", cli, szAddr);
        !            54:                        }
        !            55: 
        !            56:                if (startSession(cli, szAddr)) {
        !            57:                        close(cli);
        !            58:                        VERB(1) syslog(LOG_DEBUG, "Terminated client with socket=%d", cli);
        !            59:                        continue;
        !            60:                }
        !            61:        }
        !            62: 
1.1.2.2   misho      63:        return 0;
                     64: }

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