... | ... |
@@ -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 | 287 |
goto send_it; |
287 | 288 |
} |
288 | 289 |
get_fd: |
290 |
+ /* todo: see if this is not the same process holding |
|
291 |
+ * c and if so send directly on c->fd */ |
|
289 | 292 |
DBG("tcp_send: tcp connection found, acquiring fd\n"); |
290 | 293 |
/* get the fd */ |
291 | 294 |
response[0]=(long)c; |
292 | 295 |
response[1]=CONN_GET_FD; |
293 | 296 |
n=write(unix_tcp_sock, response, sizeof(response)); |
294 | 297 |
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); |
|
298 |
+ n=receive_fd(unix_tcp_sock, &c, sizeof(c), &fd); |
|
299 |
+ DBG("tcp_send: after receive_fd: c= %p n=%d fd=%d\n",c, n, fd); |
|
297 | 300 |
|
298 | 301 |
|
299 | 302 |
|
300 | 303 |
send_it: |
301 | 304 |
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); |
|
305 |
+ n=write(fd, buf, len); |
|
306 |
+ DBG("tcp_send: after write: c= %p n=%d fd=%d\n",c, n, fd); |
|
307 |
+ close(fd); |
|
305 | 308 |
tcpconn_put(c); /* release c (lock; dec refcnt; unlock) */ |
306 | 309 |
return n; |
307 | 310 |
} |