void CloseClient(LocalSocketClient client)
        {
            client.Close();
            _clients.Update(l => l.Remove(client));

            ClientDisconnected.OnNext(client);
        }
        void Listen(object param)
        {
            try
            {
                var listener = (TcpListener)param;
                while (_continueListening)
                {
                    if (!listener.Pending())
                    {
                        Thread.Sleep(50);
                        continue;
                    }

                    try
                    {
                        var client = new LocalSocketClient(listener.AcceptTcpClient(), CloseClient);

                        _clients.OnNext(_clients.Value.Add(client));

                        try
                        {
                            ClientConnected.OnNext(client);
                        }
                        catch (Exception e)
                        {
                            // TODO Log
                            _report.Exception("Failed to handle client connection", e);
                            continue;
                        }
                    }
                    catch (InvalidOperationException e)
                    {
                        // TODO: Log
                        _report.Exception("", e);
                        continue;
                    }
                    catch (SocketException e)
                    {
                        // TODO: Log
                        _report.Exception("", e);
                        continue;
                    }
                }
            }
            catch (Exception e)
            {
                // TODO: Log
                _report.Exception("", e);
                Close();
            }
            finally
            {
                _hasStoppedListening.Set();
            }
        }