I know at least one CL platform, LispWorks, has some related API (HCL:ADD-SPECIAL-FREE-ACTION) [1], and I want to use it in my UDP applications. Just don't know if this will be a common feature to be considered by usocket itself.
It doesn't need to be applied to other backends in general, however, it does need to be applied to all implementations which make direct use of the handles (non-lisp objects) supplied by the operating system.
The usual terminology for this kind of stuff is "finalizers". What you could do, is to add a finalizer that signals a warning if a socket object is going to be garbage collected that wasn't closed previously.
Right. However, implementations which provide objects for this purpose should take care of this themselves because usocket uses the implementation supplied sockets. Only in those cases where such guarantees are missing, usocket needs to take additional measures. This includes LispWorks, but additional investigation will turn up if this is the only implementation affected.
I'm quite sure that only UDP stuff being affected (which haven't been merged into USOCKET). For TCP, the CL implementation itself will take good care of TCP streams and close the socket fd when streams being GCed.
After more investigation, I think there're two implementations of five (CMUCL, ECL/SBCL, CCL, Allegro CL, LispWorks) need consider this issue: LispWorks and CMUCL. They both operate on raw socket fd.
For LispWorks, I've done my idea on USOCKET-UDP: add a special free action on DATAGRAM-USOCKET, when it's getting GCed, SOCKET-CLOSE will be called on it, and I have to add a new CLOSED-P slot for LispWorks on DATAGRAM-USOCKET to avoid multiple call of SOCKET-CLOSE. See this:
http://cl-net-snmp.svn.sourceforge.net/viewvc/cl-net-snmp/usocket-udp/trunk/...
Test on LispWorks shows above code can work: I create many unconnected DATAGRAM-USOCKET instances but not assign them to any variable. After some time and make sure no */**/*** still point to these instances, do a (HCL:GC-ALL) can get all these socket-fd be closed correctly. I think the issue solved (on LispWorks).
Don't know if CMUCL has related function to do the same thing (yet).
-- binghe