Re: [Haskell-cafe] Socket not released
You need to close the parent's socket in the child fork, as well as the parent - if it's inherited by the child, it's held open there, even if the parent closes it. Thanks! That did the trick. I did so by adding close_fds = True to the CreateProcess record. However the documentation of System.Process says that this only works on Windows if std_in, std_out, and std_err are all set to Inherit. This is not the case in my program so it will not work on any nodes that run on Windows. What is the workaround for doing this kind of thing in Windows? Also since the file descriptor of the socket appears to be inherited by the child process, can I just start using it rather than closing it in both the parent and child and then creating a new one? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Socket not released
Quoth Jonathan Geddes geddes.jonat...@gmail.com, You need to close the parent's socket in the child fork, as well as the parent - if it's inherited by the child, it's held open there, even if the parent closes it. Thanks! That did the trick. I did so by adding close_fds = True to the CreateProcess record. However the documentation of System.Process says that this only works on Windows if std_in, std_out, and std_err are all set to Inherit. This is not the case in my program so it will not work on any nodes that run on Windows. What is the workaround for doing this kind of thing in Windows? Only a guess, but I predict that it will work for your purposes, since you're not concerned about what happens to std_in et al. That statement in the documentation is ambiguous, so if it isn't convenient to just test for this, you need someone to clarify what doesn't work means. Also since the file descriptor of the socket appears to be inherited by the child process, can I just start using it rather than closing it in both the parent and child and then creating a new one? Sure! At least from a POSIX perspective, and it would be surprising if a Haskell implementation failed to preserve that. Donn Cave, d...@avvanta.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Socket not released
Only a guess, but I predict that it will work for your purposes, since you're not concerned about what happens to std_in et al. I actually am concerned about what happens to std_in. The parent process serializes a bit of state and passes it to the child via the child's std_in. There's probably a better way to do such a thing, but it works for now. That statement in the documentation is ambiguous, so if it isn't convenient to just test for this, you need someone to clarify what doesn't work means. I will wait to test this when (and if) I have to put a node on a Windows box. Sure! At least from a POSIX perspective, and it would be surprising if a Haskell implementation failed to preserve that. If only I knew for sure that all nodes would remain in the POSIX world. I appreciate the help. --Jonathan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Socket not released
Cafe, I'm writing a network application that uses static configuration a la xmonad and yi. When the app receives a certain command it recompiles its source, closes the socket it is using and runs its newly compiled predecessor as a new process. The problem I'm having is that the port that the parent process was using is not available to the child process. Even though the parent process has terminated, the port is unusable until the child process also terminates. Can anyone give me a clue about what's going on here? I'm using Network and System.Process modules and ruining on Ubuntu linux. I'm using the sClose function to close the socket. Thanks for any tips. --Jonathan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Socket not released
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 8/7/10 20:06 , Jonathan Geddes wrote: The problem I'm having is that the port that the parent process was using is not available to the child process. Even though the parent process has terminated, the port is unusable until the child process also terminates. Are you certain of this part? The usual problem with this kind of program is that the system holds the socket open for a minute or so in case there are any packets in flight for the connection (the lower level network protocols not being 100% reliable). And the workaround is to set SO_REUSEADDR before binding the port; in Haskell, setSocketOption socket ReuseAddr 1 - -- brandon s. allbery [linux,solaris,freebsd,perl] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkxd96oACgkQIn7hlCsL25WySACfVmlN/01XGy4LORpdi+N9ZC+x Rd8An2ccUuh7XWdh0krnf70t+kqYolOM =dbL9 -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Socket not released
Thank you for your response Are you certain of this part? The usual problem with this kind of program is that the system holds the socket open for a minute or so in case there are any packets in flight for the connection (the lower level network protocols not being 100% reliable). I'm not certain, but here's what I'm seeing. The process tries n times to acquire the socket, pausing for a second or so between attempts. While running a child process I will run a fresh process so that the two processes are competing for the socket, but neither of them are getting it. In half a dozen such test cases the fresh process grabs the socket on the very next attempt after the child process is interrupted. But if I interrupt the fresh process, the child process continues to fail to acquire the socket. And the workaround is to set SO_REUSEADDR before binding the port; in Haskell, setSocketOption socket ReuseAddr 1 I'm using the Network Module which sets ReuseAddr, according to its documentation. --Jonathan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Socket not released
Quoth Jonathan Geddes geddes.jonat...@gmail.com, ... but here's what I'm seeing. The process tries n times to acquire the socket, pausing for a second or so between attempts. While running a child process I will run a fresh process so that the two processes are competing for the socket, but neither of them are getting it. In half a dozen such test cases the fresh process grabs the socket on the very next attempt after the child process is interrupted. But if I interrupt the fresh process, the child process continues to fail to acquire the socket. You need to close the parent's socket in the child fork, as well as the parent - if it's inherited by the child, it's held open there, even if the parent closes it. Donn Cave, d...@avvanta.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe