This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Closing TCP client sockets?


Hi
We are running a Socket Server under eCos. Before we only used UDP
sockets and everything went fine. To improve reliability we are now
using TCP sockets instead. We sometimes restart the server for example
when changing the IP address of the server. In that case we close all
the client sockets that we 'accepted' and then close the listen socket.
When starting the server again and try to bind & listen again. We get a
'address already in use error' on bind.
This is when there was a client socket not closed from the client side.
When no client sockets are open everything goes fine.
We use the following code when closing the TCP client sockets
if (s != INVALID_SOCKET)
	 {
		
	 	if (shutdown (s, SHUT_RDWR))
			 DEBUGTRACE(("Socket %d shutdown\n",s));
		 else
			 DEBUGTRACE(("Socket %d not able to shutdown %u
\n",s,errno));

		struct ifreq ifr;
		memset(&ifr, 0, sizeof(struct ifreq));
		strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); // 'eth0'
interface
		// (a) get current address
		if(-1 == ioctl(s, SIOCGIFADDR, &ifr))
		{
			DEBUGTRACE(("Unable to obtain IP address\n"));
		}
		// (b) delete current address
		if(-1 == ioctl(s, SIOCDIFADDR, &ifr))
		{
			// this isn't a critical error, so no need to
close socket and return
			DEBUGTRACE(("Unable to remove IP address\n"));
		}
		
      return close (s);

	 }
    return false;
} 
We also see that the shutdown for the client socket return an error.
So question is : How should I close a TCP client socket in an orderly
fashion, when the client doesn't. In order to bind the listen socket
again later?
Alex Lindeijer | 3D perception AS
Senior System Designer
alex.l@3d-perception.com
T: +47 97540959 

www.3D-perception.com
Achieving Your Vision


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]