Browse code

- more tcp error checking

Andrei Pelinescu-Onciul authored on 29/01/2003 16:14:13
Showing 2 changed files
... ...
@@ -327,7 +327,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
327 327
 	}
328 328
 #ifdef USE_TCP
329 329
 	 else if (proto==PROTO_TCP){
330
-		if (tcp_send(buf, len, to, 0)==-1){
330
+		if (tcp_send(buf, len, to, 0)<0){
331 331
 				ser_error=E_SEND;
332 332
 				p->errors++;
333 333
 				p->ok=0;
... ...
@@ -495,7 +495,7 @@ int forward_reply(struct sip_msg* msg)
495 495
 			DBG("forward_reply: id= %x\n", id);
496 496
 		}		
497 497
 				
498
-		if (tcp_send(new_buf, new_len,  to, id)==-1)
498
+		if (tcp_send(new_buf, new_len,  to, id)<0)
499 499
 		{
500 500
 			STATS_TX_DROPS;
501 501
 			goto error;
... ...
@@ -275,16 +275,26 @@ no_id:
275 275
 			/* create tcp connection */
276 276
 			if ((c=tcpconn_connect(to))==0){
277 277
 				LOG(L_ERR, "ERROR: tcp_send: connect failed\n");
278
-				return 0;
278
+				return -1;
279 279
 			}
280 280
 			c->refcnt++;
281
+			fd=c->s;
281 282
 			
282 283
 			/* send the new tcpconn to "tcp main" */
283 284
 			response[0]=(long)c;
284 285
 			response[1]=CONN_NEW;
285 286
 			n=write(unix_tcp_sock, response, sizeof(response));
287
+			if (n<0){
288
+				LOG(L_ERR, "BUG: tcp_send: failed write: %s (%d)\n",
289
+						strerror(errno), errno);
290
+				goto end;
291
+			}	
286 292
 			n=send_fd(unix_tcp_sock, &c, sizeof(c), c->s);
287
-			fd=c->s;
293
+			if (n<0){
294
+				LOG(L_ERR, "BUG: tcp_send: failed send_fd: %s (%d)\n",
295
+						strerror(errno), errno);
296
+				goto end;
297
+			}
288 298
 			goto send_it;
289 299
 		}
290 300
 get_fd:
... ...
@@ -295,8 +305,18 @@ get_fd:
295 295
 			response[0]=(long)c;
296 296
 			response[1]=CONN_GET_FD;
297 297
 			n=write(unix_tcp_sock, response, sizeof(response));
298
+			if (n<0){
299
+				LOG(L_ERR, "BUG: tcp_send: failed to get fd(write):%s (%d)\n",
300
+						strerror(errno), errno);
301
+				goto release_c;
302
+			}
298 303
 			DBG("tcp_send, c= %p, n=%d\n", c, n);
299 304
 			n=receive_fd(unix_tcp_sock, &c, sizeof(c), &fd);
305
+			if (n<0){
306
+				LOG(L_ERR, "BUG: tcp_send: failed to get fd(receive_fd):"
307
+							" %s (%d)\n", strerror(errno), errno);
308
+				goto release_c;
309
+			}
300 310
 			DBG("tcp_send: after receive_fd: c= %p n=%d fd=%d\n",c, n, fd);
301 311
 		
302 312
 	
... ...
@@ -305,7 +325,9 @@ send_it:
305 305
 	DBG("tcp_send: sending...\n");
306 306
 	n=write(fd, buf, len);
307 307
 	DBG("tcp_send: after write: c= %p n=%d fd=%d\n",c, n, fd);
308
+end:
308 309
 	close(fd);
310
+release_c:
309 311
 	tcpconn_put(c); /* release c (lock; dec refcnt; unlock) */
310 312
 	return n;
311 313
 }