Browse Source

jsonrpcs: reworked closing tcp socket

Daniel-Constantin Mierla 4 months ago
parent
commit
d965b9242b
1 changed files with 3 additions and 4 deletions
  1. 3 4
      src/modules/jsonrpcs/jsonrpcs_sock.c

+ 3 - 4
src/modules/jsonrpcs/jsonrpcs_sock.c

@@ -830,6 +830,9 @@ int jsonrpc_tcp_process(void)
 	LM_DBG("waiting for client connections\n");
 	LM_DBG("waiting for client connections\n");
 	while(1) {
 	while(1) {
 		cfg_update();
 		cfg_update();
+		if(csock >= 0) {
+			close(csock);
+		}
 		csock = accept(
 		csock = accept(
 				_jsonrpc_tcp_address.tsock, (struct sockaddr *)&caddr, &clen);
 				_jsonrpc_tcp_address.tsock, (struct sockaddr *)&caddr, &clen);
 
 
@@ -845,12 +848,10 @@ int jsonrpc_tcp_process(void)
 		n = read(csock, jsonrpc_tcp_buf, JSONRPC_DGRAM_BUF_SIZE - 1);
 		n = read(csock, jsonrpc_tcp_buf, JSONRPC_DGRAM_BUF_SIZE - 1);
 		if(n < 0) {
 		if(n < 0) {
 			LM_ERR("failed reading from tcp socket\n");
 			LM_ERR("failed reading from tcp socket\n");
-			close(csock);
 			continue;
 			continue;
 		}
 		}
 		if(n == 0) {
 		if(n == 0) {
 			LM_DBG("no data received\n");
 			LM_DBG("no data received\n");
-			close(csock);
 			continue;
 			continue;
 		}
 		}
 		LM_DBG("data received - size: %d\n", n);
 		LM_DBG("data received - size: %d\n", n);
@@ -892,7 +893,6 @@ int jsonrpc_tcp_process(void)
 			if(n < 0) {
 			if(n < 0) {
 				LM_ERR("failed to send the response\n");
 				LM_ERR("failed to send the response\n");
 			}
 			}
-			close(csock);
 			continue;
 			continue;
 		}
 		}
 
 
@@ -900,7 +900,6 @@ int jsonrpc_tcp_process(void)
 		if(n < 0) {
 		if(n < 0) {
 			LM_ERR("failed to send the response\n");
 			LM_ERR("failed to send the response\n");
 		}
 		}
-		close(csock);
 	}
 	}
 
 
 	return 0;
 	return 0;