File:  [ELWIX - Embedded LightWeight unIX -] / mqtt / src / utils.c
Revision 1.2.2.4: download - view: text, annotated - select for diffs - revision graph
Wed Apr 25 16:55:33 2012 UTC (12 years, 3 months ago) by misho
Branches: mqtt1_1
fix "uninitialized check" reported from valgrind ...

    1: #include "global.h"
    2: 
    3: 
    4: int
    5: srv_Socket(cfg_root_t * __restrict cfg)
    6: {
    7: 	int s = -1, n = 1;
    8: 	ait_val_t v;
    9: 	u_short port;
   10: 	io_sockaddr_t sa = {{ 0 }};
   11: 
   12: 	ioTRACE(2);
   13: 
   14: 	assert(cfg);
   15: 
   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);
   20: 	if (!io_gethostbyname(AIT_GET_STR(&v), port, &sa)) {
   21: 		ioLIBERR(io);
   22: 		AIT_FREE_VAL(&v);
   23: 		return -1;
   24: 	} else
   25: 		AIT_FREE_VAL(&v);
   26: 
   27: 	s = socket(sa.ss.ss_family, SOCK_STREAM, 0);
   28: 	if (s == -1) {
   29: 		ioSYSERR(0);
   30: 		return -1;
   31: 	}
   32: 	if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof n) == -1) {
   33: 		ioSYSERR(0);
   34: 		close(s);
   35: 		return -1;
   36: 	}
   37: 	if (bind(s, &sa.sa, sa.sa.sa_len) == -1) {
   38: 		ioSYSERR(0);
   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>