Commits

Roger Light committed c8d9b22

No need to set socket blocking again.

  • Participants
  • Parent commits d1fed7f
  • Branches 1.3.1

Comments (0)

Files changed (3)

 
 		if(!blocking){
 			/* Set non-blocking */
-			if(_mosquitto_socket_nonblock(*sock, 1)){
+			if(_mosquitto_socket_nonblock(*sock)){
 				COMPAT_CLOSE(*sock);
 				continue;
 			}
 		if(rc == 0 || errno == EINPROGRESS || errno == COMPAT_EWOULDBLOCK){
 			if(blocking){
 				/* Set non-blocking */
-				if(_mosquitto_socket_nonblock(*sock, 1)){
+				if(_mosquitto_socket_nonblock(*sock)){
 					COMPAT_CLOSE(*sock);
 					continue;
 				}
 	return rc;
 }
 
-int _mosquitto_socket_nonblock(int sock, int nonblock)
+int _mosquitto_socket_nonblock(int sock)
 {
 #ifndef WIN32
+	int opt;
 	/* Set non-blocking */
-	nonblock = fcntl(sock, F_GETFL, 0);
-	if(nonblock == -1 || fcntl(sock, F_SETFL, nonblock | O_NONBLOCK) == -1){
+	opt = fcntl(sock, F_GETFL, 0);
+	if(opt == -1){
+		COMPAT_CLOSE(sock);
+		return 1;
+	}
+	if(fcntl(sock, F_SETFL, opt | O_NONBLOCK) == -1){
 		/* If either fcntl fails, don't want to allow this client to connect. */
 		COMPAT_CLOSE(sock);
 		return 1;
 	}
 #else
-	if(ioctlsocket(sock, FIONBIO, &nonblock)){
+	opt = 1;
+	if(ioctlsocket(sock, FIONBIO, &opt)){
 		COMPAT_CLOSE(sock);
 		return 1;
 	}
 			continue;
 		}
 
-		if(_mosquitto_socket_nonblock(listensock, 1)){
+		if(_mosquitto_socket_nonblock(listensock)){
 			continue;
 		}
 
 			COMPAT_CLOSE(listensock);
 			continue;
 		}
-		if(_mosquitto_socket_nonblock(spR, 1)){
+		if(_mosquitto_socket_nonblock(spR)){
 			COMPAT_CLOSE(listensock);
 			continue;
 		}
 			}
 		}
 
-		if(_mosquitto_socket_nonblock(spW, 1)){
+		if(_mosquitto_socket_nonblock(spW)){
 			COMPAT_CLOSE(spR);
 			COMPAT_CLOSE(listensock);
 			continue;
 	if(socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1){
 		return MOSQ_ERR_ERRNO;
 	}
-	if(_mosquitto_socket_nonblock(sv[0], 1)){
+	if(_mosquitto_socket_nonblock(sv[0])){
 		COMPAT_CLOSE(sv[0]);
 		COMPAT_CLOSE(sv[1]);
 		return MOSQ_ERR_ERRNO;
 	}
-	if(_mosquitto_socket_nonblock(sv[1], 1)){
+	if(_mosquitto_socket_nonblock(sv[1])){
 		COMPAT_CLOSE(sv[0]);
 		COMPAT_CLOSE(sv[1]);
 		return MOSQ_ERR_ERRNO;
 int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking);
 int _mosquitto_socket_close(struct mosquitto *mosq);
 int _mosquitto_try_connect(const char *host, uint16_t port, int *sock, const char *bind_address, bool blocking);
-int _mosquitto_socket_nonblock(int sock, int nonblock);
+int _mosquitto_socket_nonblock(int sock);
 int _mosquitto_socketpair(int *sp1, int *sp2);
 
 int _mosquitto_read_byte(struct _mosquitto_packet *packet, uint8_t *byte);
 	g_socket_connections++;
 #endif
 
-	if(_mosquitto_socket_nonblock(new_sock, 1)){
+	if(_mosquitto_socket_nonblock(new_sock)){
 		return INVALID_SOCKET;
 	}
 
 		ss_opt = 1;
 		setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &ss_opt, sizeof(ss_opt));
 
-		if(_mosquitto_socket_nonblock(sock, 1)){
+		if(_mosquitto_socket_nonblock(sock)){
 			return 1;
 		}