2020-01-18 08:38:21 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2019-07-27 08:21:25 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-08-06 16:09:39 +00:00
|
|
|
#include <LibCore/EventReceiver.h>
|
2020-02-06 14:04:03 +00:00
|
|
|
#include <LibCore/Notifier.h>
|
2019-07-27 08:21:25 +00:00
|
|
|
|
2020-02-02 11:34:39 +00:00
|
|
|
namespace Core {
|
2019-07-27 08:21:25 +00:00
|
|
|
|
2023-08-06 16:09:39 +00:00
|
|
|
class LocalServer : public EventReceiver {
|
2020-02-02 11:34:39 +00:00
|
|
|
C_OBJECT(LocalServer)
|
2019-07-27 08:21:25 +00:00
|
|
|
public:
|
2020-02-02 11:34:39 +00:00
|
|
|
virtual ~LocalServer() override;
|
2019-07-27 08:21:25 +00:00
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
ErrorOr<void> take_over_from_system_server(ByteString const& path = ByteString());
|
2024-04-26 21:17:51 +00:00
|
|
|
ErrorOr<void> take_over_fd(int socket_fd);
|
2019-07-27 08:21:25 +00:00
|
|
|
bool is_listening() const { return m_listening; }
|
2023-12-16 14:19:34 +00:00
|
|
|
bool listen(ByteString const& address);
|
2019-07-27 08:21:25 +00:00
|
|
|
|
2023-02-08 22:05:44 +00:00
|
|
|
ErrorOr<NonnullOwnPtr<LocalSocket>> accept();
|
2019-07-27 08:21:25 +00:00
|
|
|
|
2023-02-08 22:05:44 +00:00
|
|
|
Function<void(NonnullOwnPtr<LocalSocket>)> on_accept;
|
2022-11-08 14:30:25 +00:00
|
|
|
Function<void(Error)> on_accept_error;
|
2019-07-27 08:21:25 +00:00
|
|
|
|
|
|
|
private:
|
2023-08-06 16:09:39 +00:00
|
|
|
explicit LocalServer(EventReceiver* parent = nullptr);
|
2019-09-21 08:46:55 +00:00
|
|
|
|
2019-11-26 16:27:21 +00:00
|
|
|
void setup_notifier();
|
|
|
|
|
2019-07-27 08:21:25 +00:00
|
|
|
int m_fd { -1 };
|
|
|
|
bool m_listening { false };
|
2020-02-02 11:34:39 +00:00
|
|
|
RefPtr<Notifier> m_notifier;
|
2019-07-27 08:21:25 +00:00
|
|
|
};
|
2020-02-02 11:34:39 +00:00
|
|
|
|
|
|
|
}
|