summaryrefslogtreecommitdiff
path: root/Libraries/LibCore/CTCPServer.h
blob: 4f17f61801f691150530f52e160225540ce3b7ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once

#include <AK/IPv4Address.h>
#include <LibCore/CNotifier.h>
#include <LibCore/CObject.h>

class CTCPSocket;

class CTCPServer : public CObject {
    C_OBJECT(CTCPServer)
public:
    virtual ~CTCPServer() override;

    bool is_listening() const { return m_listening; }
    bool listen(const IPv4Address& address, u16 port);

    RefPtr<CTCPSocket> accept();

    IPv4Address local_address();
    u16 local_port();

    Function<void()> on_ready_to_accept;

private:
    explicit CTCPServer(CObject* parent = nullptr);

    int m_fd { -1 };
    bool m_listening { false };
    RefPtr<CNotifier> m_notifier;
};