+ rf <- newIORef B.empty
+ h <- S.socketToHandle s ReadWriteMode
+ return Client { socket=h, rbuf=rf }
+
+-- | Creates and returns a server endpoint.
+getServer :: FilePath -> IO S.Socket
+getServer path = do
+ s <- S.socket S.AF_UNIX S.Stream S.defaultProtocol
+ S.bindSocket s (S.SockAddrUnix path)
+ S.listen s 5 -- 5 is the max backlog
+ return s
+
+-- | Closes a server endpoint.
+-- FIXME: this should be encapsulated into a nicer type.
+closeServer :: FilePath -> S.Socket -> IO ()
+closeServer path sock = do
+ S.sClose sock
+ removeFile path
+
+-- | Accepts a client
+acceptClient :: S.Socket -> IO Client
+acceptClient s = do
+ -- second return is the address of the client, which we ignore here
+ (client_socket, _) <- S.accept s
+ new_buffer <- newIORef B.empty
+ handle <- S.socketToHandle client_socket ReadWriteMode
+ return Client { socket=handle, rbuf=new_buffer }