Browse code

- tcp bugfixes

Andrei Pelinescu-Onciul authored on 28/01/2003 16:46:44
Showing 3 changed files
... ...
@@ -68,3 +68,5 @@ x freopen stdin, stdout, stderr to /dev/null
68 68
 - add src_port, dst_port, proto to cfg.{y,lex}
69 69
 x generic locking lib
70 70
 - convert tm to use new locking lib
71
+- tcp disable nagle & other socket stuff (close()?)
72
+
... ...
@@ -76,7 +76,7 @@ struct tcp_req{
76 76
 
77 77
 struct tcp_connection{
78 78
 	int s; /*socket, used by "tcp main" */
79
-	int fd; /* used only by "children" */
79
+	int fd; /* used only by "children", don't modify it! private data! */
80 80
 	int id; /* id (unique!) used to retrieve a specific connection when
81 81
 	           reply-ing*/
82 82
 	struct receive_info rcv; /* src & dst ip, ports, proto a.s.o*/
... ...
@@ -101,7 +101,7 @@ struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
101 101
 		goto error;
102 102
 	}
103 103
 	c->s=sock;
104
-	c->fd=sock;
104
+	c->fd=-1; /* not initialized */
105 105
 	c->rcv.src_su=*su;
106 106
 	
107 107
 	c->refcnt=0;
... ...
@@ -241,6 +241,7 @@ int tcp_send(char* buf, unsigned len, union sockaddr_union* to, int id)
241 241
 	struct tcp_connection *c;
242 242
 	struct ip_addr ip;
243 243
 	int port;
244
+	int fd;
244 245
 	long response[2];
245 246
 	int n;
246 247
 	
... ...
@@ -286,22 +287,24 @@ no_id:
286 286
 			goto send_it;
287 287
 		}
288 288
 get_fd:
289
+			/* todo: see if this is not the same process holding
290
+			 *  c  and if so send directly on c->fd */
289 291
 			DBG("tcp_send: tcp connection found, acquiring fd\n");
290 292
 			/* get the fd */
291 293
 			response[0]=(long)c;
292 294
 			response[1]=CONN_GET_FD;
293 295
 			n=write(unix_tcp_sock, response, sizeof(response));
294 296
 			DBG("tcp_send, c= %p, n=%d\n", c, n);
295
-			n=receive_fd(unix_tcp_sock, &c, sizeof(c), &c->fd);
296
-			DBG("tcp_send: after receive_fd: c= %p n=%d fd=%d\n",c, n, c->fd);
297
+			n=receive_fd(unix_tcp_sock, &c, sizeof(c), &fd);
298
+			DBG("tcp_send: after receive_fd: c= %p n=%d fd=%d\n",c, n, fd);
297 299
 		
298 300
 	
299 301
 	
300 302
 send_it:
301 303
 	DBG("tcp_send: sending...\n");
302
-	n=write(c->fd, buf, len);
303
-	DBG("tcp_send: after write: c= %p n=%d fd=%d\n",c, n, c->fd);
304
-	close(c->fd);
304
+	n=write(fd, buf, len);
305
+	DBG("tcp_send: after write: c= %p n=%d fd=%d\n",c, n, fd);
306
+	close(fd);
305 307
 	tcpconn_put(c); /* release c (lock; dec refcnt; unlock) */
306 308
 	return n;
307 309
 }