Browse code

- tcp_send fix: return <0 on send error. This is a modified version of Klaus Darilion patch/openser port (extra tcpconn_put on release error)

Andrei Pelinescu-Onciul authored on 22/02/2006 12:45:24
Showing 1 changed files
... ...
@@ -729,7 +729,9 @@ void tcpconn_put(struct tcp_connection* c)
729 729
 
730 730
 
731 731
 
732
-/* finds a tcpconn & sends on it */
732
+/* finds a tcpconn & sends on it
733
+ * returns: number of bytes written (>=0) on success
734
+ *          <0 on error */
733 735
 int tcp_send(int type, char* buf, unsigned len, union sockaddr_union* to,
734 736
 				int id)
735 737
 {
... ...
@@ -848,13 +850,14 @@ send_it:
848 850
 		/* tell "main" it should drop this (optional it will t/o anyway?)*/
849 851
 		response[0]=(long)c;
850 852
 		response[1]=CONN_ERROR;
851
-		n=send_all(unix_tcp_sock, response, sizeof(response));
852
-		/* CONN_ERROR will auto-dec refcnt => we must not call tcpconn_put !!*/
853
-		if (n<=0){
853
+		if (send_all(unix_tcp_sock, response, sizeof(response))<=0){
854 854
 			LOG(L_ERR, "BUG: tcp_send: error return failed (write):%s (%d)\n",
855 855
 					strerror(errno), errno);
856
+			tcpconn_put(c); /* deref. it manually */
856 857
 			n=-1;
857 858
 		}
859
+		/* CONN_ERROR will auto-dec refcnt => we must not call tcpconn_put 
860
+		 * if it succeeds */
858 861
 		close(fd);
859 862
 		return n; /* error return, no tcpconn_put */
860 863
 	}