Closing a socket.

Thomas Rauscher trauscher at loytec.com
Wed May 11 16:00:07 UTC 2005


 
  

> -----Original Message-----
> From: Chris Johns [mailto:chrisj at rtems.org] 
> Sent: Wednesday, May 11, 2005 2:34 AM
> To: RTEMS Users
> Subject: Closing a socket.
> 
> Hello,
> 
> Can a socket be closed by one thread while another thread is 
> blocked in the socket (soconnsleep) ?
> 
> If not does a way exist to wake the blocked thread or should 
> the thread be deleted before closing the socket ?
> 

Maybe there is a race condition (visual check against 4.6.2).
Please correct me if I'm wrong.

If rtems_bsdnet_close is called, the socket is freed in
soclose (depends on socket state, protocol used, ...).
The waiting thread might wake up later (depends on
scheduling) and could access so->so_pgid in soconnsleep().
Bad things would happen if this memory area is now 
used for something else...
I remember having seen this in an accept/close race
(rtems 4.5).

A clean (and portable) way is to send a 
"QUIT" message to the socket so that the blocking
thread can stop using the socket.

TCP connections can be closed with shutdown().

Regards,
Thomas Rauscher

--
Thomas Rauscher
LOYTEC electronics GmbH




More information about the users mailing list