File:  [ELWIX - Embedded LightWeight unIX -] / mqtt / src / client.c
Revision 1.1.2.4: download - view: text, annotated - select for diffs - revision graph
Tue Dec 13 14:57:15 2011 UTC (12 years, 6 months ago) by misho
Branches: mqtt1_0
added send connect

    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: }
   22: 
   23: int
   24: try2Connect(int sock)
   25: {
   26: 	int siz = 0;
   27: 
   28: 	siz = mqtt_msgCONNECT(args->msg, AIT_GET_STR(&args->ConnID), AIT_GET_STR(&args->User), 
   29: 			AIT_GET_STR(&args->Pass), args->Will.Topic.val.string, 
   30: 			args->Will.Msg.val.string, args->Clear, args->QoS, args->Retain);
   31: 	if (siz == -1) {
   32: 		printf("Error:: msgCONNECT #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());
   33: 		return -1;
   34: 	}
   35: 
   36: 	siz = send(sock, args->msg->msg_base, siz, 0);
   37: 	if (siz == -1) {
   38: 		printf("Error:: send() #%d - %s\n", errno, strerror(errno));
   39: 		return -1;
   40: 	} else
   41: 		VERB(3) printf("Sended CONNECT %d bytes\n", siz);
   42: 
   43: 	return siz;
   44: }

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