Annotation of mqtt/src/client.c, revision 1.1.2.6

1.1.2.1   misho       1: #include "global.h"
                      2: #include "mqtt.h"
                      3: 
                      4: 
                      5: int
                      6: InitClient(void)
                      7: {
                      8:        int sock;
                      9: 
                     10:        sock = socket(args->addr.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
                     11:        if (sock == -1) {
                     12:                printf("Error:: socket() #%d - %s\n", errno, strerror(errno));
                     13:                return -1;
                     14:        }
                     15:        if (connect(sock, &args->addr.sa, args->addr.sa.sa_len) == -1) {
                     16:                printf("Error:: connect() #%d - %s\n", errno, strerror(errno));
                     17:                return -1;
                     18:        }
                     19: 
                     20:        return sock;
                     21: }
1.1.2.2   misho      22: 
                     23: int
1.1.2.4   misho      24: try2Connect(int sock)
1.1.2.2   misho      25: {
1.1.2.4   misho      26:        int siz = 0;
1.1.2.6 ! misho      27:        struct pollfd pfd;
1.1.2.4   misho      28: 
1.1.2.6 ! misho      29:        printf("ka=%d\n", args->ka);
1.1.2.5   misho      30:        siz = mqtt_msgCONNECT(args->msg, AIT_GET_STR(&args->ConnID), args->ka, 
                     31:                        AIT_GET_STR(&args->User), AIT_GET_STR(&args->Pass), 
                     32:                        args->Will.Topic.val.string, args->Will.Msg.val.string, 
                     33:                        !args->notClear, args->QoS, args->Retain);
1.1.2.4   misho      34:        if (siz == -1) {
                     35:                printf("Error:: msgCONNECT #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());
                     36:                return -1;
                     37:        }
                     38: 
                     39:        siz = send(sock, args->msg->msg_base, siz, 0);
                     40:        if (siz == -1) {
                     41:                printf("Error:: send() #%d - %s\n", errno, strerror(errno));
                     42:                return -1;
                     43:        } else
                     44:                VERB(3) printf("Sended CONNECT %d bytes\n", siz);
                     45: 
1.1.2.6 ! misho      46:        printf("ka=%d\n", args->ka);
        !            47:        pfd.fd = sock;
        !            48:        pfd.events = POLLIN;
        !            49:        switch (poll(&pfd, 1, args->ka * 1000)) {
        !            50:                case -1:
        !            51:                        printf("Error:: poll() #%d - %s\n", errno, strerror(errno));
        !            52:                        return -1;
        !            53:                case 0:
        !            54:        printf("ka=%d\n", args->ka);
        !            55:                        VERB(3) printf("Timeout reached (%d) ...\n", args->ka * 1000);
        !            56:                        return -1;
        !            57:        }
        !            58:        if (pfd.revents & (POLLERR | POLLHUP | POLLNVAL))
        !            59:                return -1;
        !            60: 
        !            61:        siz = recv(sock, args->msg->msg_base, args->msg->msg_len, 0);
        !            62:        if (siz == -1) {
        !            63:                printf("Error:: recv() #%d - %s\n", errno, strerror(errno));
        !            64:                return -1;
        !            65:        } else
        !            66:                VERB(3) printf("Received %d bytes\n", siz);
        !            67: 
        !            68:        return (u_char) mqtt_readCONNACK(args->msg);
1.1.2.2   misho      69: }

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