mirror of
https://github.com/RGBCube/serenity
synced 2025-10-25 01:22:32 +00:00
Instead of trying to support both client and server in CLocalSocket, let's
have a specialized server class.
The basic usage is:
CLocalServer server;
server.listen("/tmp/name-of-portal");
server.on_ready_to_accept = [&] {
CLocalSocket* client = server.accept();
...
};
This will make things a lot simpler, since an accepting socket doesn't need
half of the stuff that a regular CIODevice provides. :^)
25 lines
527 B
C++
25 lines
527 B
C++
#pragma once
|
|
|
|
#include <LibCore/CNotifier.h>
|
|
#include <LibCore/CObject.h>
|
|
|
|
class CLocalSocket;
|
|
|
|
class CLocalServer : public CObject {
|
|
C_OBJECT(CLocalServer)
|
|
public:
|
|
explicit CLocalServer(CObject* parent = nullptr);
|
|
virtual ~CLocalServer() override;
|
|
|
|
bool is_listening() const { return m_listening; }
|
|
bool listen(const String& address);
|
|
|
|
CLocalSocket* accept();
|
|
|
|
Function<void()> on_ready_to_accept;
|
|
|
|
private:
|
|
int m_fd { -1 };
|
|
bool m_listening { false };
|
|
OwnPtr<CNotifier> m_notifier;
|
|
};
|