Kaynağa Gözat

- more tcp error checking

Andrei Pelinescu-Onciul 22 yıl önce
ebeveyn
işleme
534092baac
2 değiştirilmiş dosya ile 26 ekleme ve 4 silme
  1. 2 2
      forward.c
  2. 24 2
      tcp_main.c

+ 2 - 2
forward.c

@@ -327,7 +327,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
 	}
 	}
 #ifdef USE_TCP
 #ifdef USE_TCP
 	 else if (proto==PROTO_TCP){
 	 else if (proto==PROTO_TCP){
-		if (tcp_send(buf, len, to, 0)==-1){
+		if (tcp_send(buf, len, to, 0)<0){
 				ser_error=E_SEND;
 				ser_error=E_SEND;
 				p->errors++;
 				p->errors++;
 				p->ok=0;
 				p->ok=0;
@@ -495,7 +495,7 @@ int forward_reply(struct sip_msg* msg)
 			DBG("forward_reply: id= %x\n", id);
 			DBG("forward_reply: id= %x\n", id);
 		}		
 		}		
 				
 				
-		if (tcp_send(new_buf, new_len,  to, id)==-1)
+		if (tcp_send(new_buf, new_len,  to, id)<0)
 		{
 		{
 			STATS_TX_DROPS;
 			STATS_TX_DROPS;
 			goto error;
 			goto error;

+ 24 - 2
tcp_main.c

@@ -275,16 +275,26 @@ no_id:
 			/* create tcp connection */
 			/* create tcp connection */
 			if ((c=tcpconn_connect(to))==0){
 			if ((c=tcpconn_connect(to))==0){
 				LOG(L_ERR, "ERROR: tcp_send: connect failed\n");
 				LOG(L_ERR, "ERROR: tcp_send: connect failed\n");
-				return 0;
+				return -1;
 			}
 			}
 			c->refcnt++;
 			c->refcnt++;
+			fd=c->s;
 			
 			
 			/* send the new tcpconn to "tcp main" */
 			/* send the new tcpconn to "tcp main" */
 			response[0]=(long)c;
 			response[0]=(long)c;
 			response[1]=CONN_NEW;
 			response[1]=CONN_NEW;
 			n=write(unix_tcp_sock, response, sizeof(response));
 			n=write(unix_tcp_sock, response, sizeof(response));
+			if (n<0){
+				LOG(L_ERR, "BUG: tcp_send: failed write: %s (%d)\n",
+						strerror(errno), errno);
+				goto end;
+			}	
 			n=send_fd(unix_tcp_sock, &c, sizeof(c), c->s);
 			n=send_fd(unix_tcp_sock, &c, sizeof(c), c->s);
-			fd=c->s;
+			if (n<0){
+				LOG(L_ERR, "BUG: tcp_send: failed send_fd: %s (%d)\n",
+						strerror(errno), errno);
+				goto end;
+			}
 			goto send_it;
 			goto send_it;
 		}
 		}
 get_fd:
 get_fd:
@@ -295,8 +305,18 @@ get_fd:
 			response[0]=(long)c;
 			response[0]=(long)c;
 			response[1]=CONN_GET_FD;
 			response[1]=CONN_GET_FD;
 			n=write(unix_tcp_sock, response, sizeof(response));
 			n=write(unix_tcp_sock, response, sizeof(response));
+			if (n<0){
+				LOG(L_ERR, "BUG: tcp_send: failed to get fd(write):%s (%d)\n",
+						strerror(errno), errno);
+				goto release_c;
+			}
 			DBG("tcp_send, c= %p, n=%d\n", c, n);
 			DBG("tcp_send, c= %p, n=%d\n", c, n);
 			n=receive_fd(unix_tcp_sock, &c, sizeof(c), &fd);
 			n=receive_fd(unix_tcp_sock, &c, sizeof(c), &fd);
+			if (n<0){
+				LOG(L_ERR, "BUG: tcp_send: failed to get fd(receive_fd):"
+							" %s (%d)\n", strerror(errno), errno);
+				goto release_c;
+			}
 			DBG("tcp_send: after receive_fd: c= %p n=%d fd=%d\n",c, n, fd);
 			DBG("tcp_send: after receive_fd: c= %p n=%d fd=%d\n",c, n, fd);
 		
 		
 	
 	
@@ -305,7 +325,9 @@ send_it:
 	DBG("tcp_send: sending...\n");
 	DBG("tcp_send: sending...\n");
 	n=write(fd, buf, len);
 	n=write(fd, buf, len);
 	DBG("tcp_send: after write: c= %p n=%d fd=%d\n",c, n, fd);
 	DBG("tcp_send: after write: c= %p n=%d fd=%d\n",c, n, fd);
+end:
 	close(fd);
 	close(fd);
+release_c:
 	tcpconn_put(c); /* release c (lock; dec refcnt; unlock) */
 	tcpconn_put(c); /* release c (lock; dec refcnt; unlock) */
 	return n;
 	return n;
 }
 }