TCPServer.h 801 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/IPv4Address.h>
  8. #include <LibCore/Notifier.h>
  9. #include <LibCore/Object.h>
  10. namespace Core {
  11. class TCPServer : public Object {
  12. C_OBJECT(TCPServer)
  13. public:
  14. virtual ~TCPServer() override;
  15. bool is_listening() const { return m_listening; }
  16. bool listen(const IPv4Address& address, u16 port);
  17. void set_blocking(bool blocking);
  18. RefPtr<TCPSocket> accept();
  19. Optional<IPv4Address> local_address() const;
  20. Optional<u16> local_port() const;
  21. Function<void()> on_ready_to_accept;
  22. private:
  23. explicit TCPServer(Object* parent = nullptr);
  24. int m_fd { -1 };
  25. bool m_listening { false };
  26. RefPtr<Notifier> m_notifier;
  27. };
  28. }