fpco / ide-backend

ide-backend drives the GHC API to build, query, and run your code
120 stars 17 forks source link

Using Unix domain sockets for RPC #314

Closed ncreep closed 8 years ago

ncreep commented 8 years ago

In the Windows support issue it was suggested to use Unix domain sockets where available. I tried to tackle this issue, here are some observations.

With plain sockets we don't need to select a port, one is chosen randomly every time. Ideally something similar should happen when using Unix sockets. There is an autobinding feature that can achieve this, but it seems to be supported only on Linux, and my rudimentary attempts of getting it to work in the code failed (but that's probably fixable).

Generally (and portably), Unix sockets use file names for communication. As an alternative to random ports, I tried creating a temporary file, this has the following complications:

I've implemented the above, and it seems to be working. But I would prefer to use some more reliable way of generating file names.

Any suggestions?

ncreep commented 8 years ago

Thinking about it, it is possible to generate a random directory for each socket, and then create the communication file there (again, noting that some of those will remain in the user's temporary directory). That should avoid the race condition mentioned above.

If that sounds reasonable, I can implement it and send a pull request.

mgsloan commented 8 years ago

Sure, that sounds reasonable to me! Feel free to implement this.