Annotation of mqtt/src/utils.c, revision 1.2.2.4

1.2       misho       1: #include "global.h"
                      2: 
                      3: 
                      4: int
1.2.2.1   misho       5: srv_Socket(cfg_root_t * __restrict cfg)
1.2       misho       6: {
                      7:        int s = -1, n = 1;
1.2.2.1   misho       8:        ait_val_t v;
1.2       misho       9:        u_short port;
1.2.2.4 ! misho      10:        io_sockaddr_t sa = {{ 0 }};
1.2       misho      11: 
                     12:        ioTRACE(2);
                     13: 
1.2.2.4 ! misho      14:        assert(cfg);
        !            15: 
1.2.2.1   misho      16:        cfg_loadAttribute(cfg, "mqttd", "port", &v, MQTT_PORT);
                     17:        port = strtol(AIT_GET_STR(&v), NULL, 0);
                     18:        AIT_FREE_VAL(&v);
                     19:        cfg_loadAttribute(cfg, "mqttd", "listen", &v, MQTT_HOST);
1.2.2.3   misho      20:        if (!io_gethostbyname(AIT_GET_STR(&v), port, &sa)) {
                     21:                ioLIBERR(io);
                     22:                AIT_FREE_VAL(&v);
1.2       misho      23:                return -1;
1.2.2.3   misho      24:        } else
                     25:                AIT_FREE_VAL(&v);
1.2       misho      26: 
1.2.2.2   misho      27:        s = socket(sa.ss.ss_family, SOCK_STREAM, 0);
1.2       misho      28:        if (s == -1) {
1.2.2.2   misho      29:                ioSYSERR(0);
1.2       misho      30:                return -1;
                     31:        }
                     32:        if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof n) == -1) {
1.2.2.2   misho      33:                ioSYSERR(0);
1.2       misho      34:                close(s);
                     35:                return -1;
                     36:        }
1.2.2.3   misho      37:        if (bind(s, &sa.sa, sa.sa.sa_len) == -1) {
1.2.2.2   misho      38:                ioSYSERR(0);
1.2       misho      39:                close(s);
                     40:                return -1;
                     41:        }
                     42: 
                     43:        return s;
                     44: }
                     45: 
                     46: int
                     47: srv_Close(int s)
                     48: {
                     49:        ioTRACE(2);
                     50: 
                     51:        if (s > STDERR_FILENO)
                     52:                shutdown(s, SHUT_RDWR);
                     53: 
                     54:        return close(s);
                     55: }

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