mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00

The C_OBJECT macro now also inserts a static construct(...) helper into the class. Now we can make the constructor(s) private and instead call: auto socket = CTCPSocket::construct(arguments); construct() returns an ObjectPtr<T>, which we'll later switch to being a NonnullRefPtr<T>, once everything else in in place for ref-counting.
26 lines
568 B
C++
26 lines
568 B
C++
#pragma once
|
|
|
|
#include <AK/IPv4Address.h>
|
|
#include <LibCore/CNotifier.h>
|
|
#include <LibCore/CObject.h>
|
|
|
|
class CTCPSocket;
|
|
|
|
class CTCPServer : public CObject {
|
|
C_OBJECT(CTCPServer)
|
|
public:
|
|
explicit CTCPServer(CObject* parent = nullptr);
|
|
virtual ~CTCPServer() override;
|
|
|
|
bool is_listening() const { return m_listening; }
|
|
bool listen(const IPv4Address& address, u16 port);
|
|
|
|
ObjectPtr<CTCPSocket> accept();
|
|
|
|
Function<void()> on_ready_to_accept;
|
|
|
|
private:
|
|
int m_fd { -1 };
|
|
bool m_listening { false };
|
|
OwnPtr<CNotifier> m_notifier;
|
|
};
|