This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
RE : RE : I lose sockets
- From: "Roger Arn " <roger dot arn at affelec dot ch>
- To: <ecos-discuss at sourceware dot org>
- Cc: <andrew at lunn dot ch>
- Date: Thu, 17 Aug 2006 09:58:04 +0200
- Subject: [ECOS] RE : [ECOS] RE : [ECOS] I lose sockets
> Ah, now i see your problem.
>
> You have the basic TCP server structure wrong. You should create one
listen'ing socket and then keep it for
> ever, repeatadly doing accept() on it as each client connects. ie you
don't need a listening socket per
> connection.
> Andrew
Now I've made the following structure (simplistic)
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
bind(hmiParameter->IPsocket, (struct sockaddr *) &local, sizeof(local));
listen(hmiParameter->IPsocket, SOMAXCONN);
Connect: accept(hmiParameter->IPsocket, (struct sockaddr *)&client_addr,
&x))
while(true) {
select(hmiParameter->client + 1, &in_fds, 0, 0, &tv);
if(read(hmiParameter->client, buf, sizeof(buf)-1) <= 0) {
goto Connect;
}
}
( remark: close(hmiParameter->IPsocket) will never be called )
But it isn't working. I still lose a socket when I close the external
application.
Remark: Theres only one external application connected. This application
will be closed and started again multiple times.
And: When I'm calling the accept() methode, it will allocate a socket
(from the socketzone) in
packages\net\bsd_tcpip\current\src\sys\netinet\tcp_input.c line 735 and
it allocates a tcpcb in the tcpcb zone. These two structures will be
attached together. Now when I'm closing the external application, it
calls the
in_pcbdetach() methode from
packages\net\bsd_tcpip\current\src\sys\netinet\in_pcb.c and deallocate
the tcpcb structure to its zone and tryes to make the same with the
detached socket struckture with calling sofree() (in_pcb.c line 530),
but the SS_NOFDREF state is wrong and it fails to add the pointer to the
socket zone.
Is still something wrong with my tcp server structure ?
Or is there a correlation with the tcp close process and I have to wait
a long time until I can reuse a socket ?
Roger
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss