title: Non-blocking ruby UNIXSocket
body: <p><em>Preamble: Obviously, I am too stupid.</em></p>
  
  <p>I want to expose a simple <code>UNIXSocket</code> in Ruby that accepts a single command from connecting clients without blocking further connections while processing until the socket is closed (which the STDLIB socket does) including a timeout for clients that do not send any command within X seconds. What I also want is to <code>Etc.getpwuid(socket.getpeereid.first).name</code>, or: Get the username of the user connecting to that socket.</p>
  
  <p>Because the default <code>UNIXSocket</code> is blocking all further connections, I have tried to do it with EventMachine and Celluloid:</p>
  
  <p><strong>EventMachine:</strong>
  Multiple connections work like a charm, but there is no way to access the client's <code>UID</code>. Also, even though you can set a client timeout, the docs do not tell anything about when this will actually be triggered. Particularily frustrating about this experience: Some methods on <code>EventMachine</code> (like <code>get_peername</code>) are not documented on any of the googleable API docs, because they are hidden inside the native extensions. Unfortunately, there is no equivalent of <code>getpeereid</code> in EventMachine even in the C-Code, so I eventually bailed on this.</p>
  
  <p><strong>Celluloid:</strong> I opened a regular UNIXSocket and then passed any opened connections to an <code>async</code> Celluloid listener. This kept accepting connections as well, but when I tried to end the server process the  Celluloid threads were not able to shut down (<code>Terminating X actors</code>), even though I did properly <code>socket.close</code> and <code>Actor.current.terminate</code> inside my <code>listen</code> method (called via <code>async.listen</code>). Only thing that remedied this was <code>kill -9</code>. Because the docs of Celluloid told me so, I also tried the <a href="https://github.com/celluloid/celluloid-io/blob/master/examples/echo_unix_client.rb" rel="nofollow"><code>celluloid-io</code> echo server example</a>, but that gave me the same result that needed <code>kill -9</code>.</p>
  
  <p>I've been thinking about firing up my own handler thread solution but those would be lacking the automatic timeout, and I was hoping someone would already have solved this seemingly basic problem.</p>
  
  <p>I hope I am missing something here. As of now my impression is that Unix Sockets on Ruby are missing the most basic ingredients :/</p>