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 848
 		/* tell "main" it should drop this (optional it will t/o anyway?)*/
849 849
 		response[0]=(long)c;
850 850
 		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){
851
+		if (send_all(unix_tcp_sock, response, sizeof(response))<=0){
854 852
 			LOG(L_ERR, "BUG: tcp_send: error return failed (write):%s (%d)\n",
855 853
 					strerror(errno), errno);
854
+			tcpconn_put(c); /* deref. it manually */
856 855
 			n=-1;
857 856
 		}
857
+		/* CONN_ERROR will auto-dec refcnt => we must not call tcpconn_put 
858
+		 * if it succeeds */
858 859
 		close(fd);
859 860
 		return n; /* error return, no tcpconn_put */
860 861
 	}