Consider the following, typed not tested, code:
import Network.Socket
import System.Mem
main = do
_ <- socket AF_INET Stream defaultProtocol
performGC
main
This program will quickly exhaust typical system limits on open file descriptors. Now this isn't supposed to be surprising but it seems to me that we could use a finalizer via System.Mem.Weak or similar but one which has enough information to know if this particular value :: Socket has already had close called and conditionally call close when that isn't the case. Am I missing something that makes this hard?
Consider the following, typed not tested, code:
This program will quickly exhaust typical system limits on open file descriptors. Now this isn't supposed to be surprising but it seems to me that we could use a finalizer via
System.Mem.Weakor similar but one which has enough information to know if this particularvalue :: Sockethas already hadclosecalled and conditionally callclosewhen that isn't the case. Am I missing something that makes this hard?