Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
Listener.hpp
Go to the documentation of this file.
1#pragma once
4#include <cstdint>
5#include <optional>
6#include <string>
7
8namespace orbit::server {
9
13class Listener {
14public:
19 explicit Listener(uint16_t port);
20
29 Listener(std::string host, uint16_t port, int backlog = 0);
30
35 void start();
36
41 std::optional<network::Socket> accept_connection();
42
47 int fd() const;
48
52 uint16_t port() const;
53
58 void close();
59
60private:
61 std::string host_;
62 uint16_t port_;
65};
66
67} // namespace server
Definition Socket.hpp:7
Listens for incoming network connections.
Definition Listener.hpp:13
void close()
Closes the listening socket, so new connections are refused instead of queueing in the backlog (used ...
void start()
Binds and starts listening.
uint16_t port() const
The port actually bound (useful when constructed with port 0).
int backlog_
Definition Listener.hpp:63
Listener(std::string host, uint16_t port, int backlog=0)
Constructs a Listener on a specific address.
uint16_t port_
Definition Listener.hpp:62
std::optional< network::Socket > accept_connection()
Accepts a new incoming connection.
network::Socket socket_
Definition Listener.hpp:64
Listener(uint16_t port)
Constructs a Listener on the specified port, on all IPv4 interfaces.
std::string host_
Definition Listener.hpp:61
int fd() const
Gets the underlying file descriptor for epoll registration.
constexpr socket_t INVALID_SOCKET_FD
Definition PlatformSocket.hpp:40
Definition Http2Session.hpp:18