Program Listing for File sockets.hpp
↰ Return to documentation for file (sockets/include/sockets/sockets.hpp)
#pragma once
#include <lib2k/non_null_owner.hpp>
#include <lib2k/synchronized.hpp>
#include <lib2k/unique_value.hpp>
#include "detail/address_family.hpp"
#include "detail/address_info.hpp"
#include "detail/byte_order.hpp"
#include "detail/message_buffer.hpp"
#include "detail/socket.hpp"
namespace c2k {
class Sockets final {
private:
Sockets();
public:
Sockets(Sockets const& other) = delete;
Sockets(Sockets&& other) noexcept = delete;
Sockets& operator=(Sockets const& other) = delete;
Sockets& operator=(Sockets&& other) noexcept = delete;
~Sockets();
[[nodiscard]] static ServerSocket create_server(
AddressFamily const address_family,
std::uint16_t const port,
std::function<void(ClientSocket)> callback,
[[maybe_unused]] Sockets const& key = instance()
) {
return ServerSocket{ address_family, port, std::move(callback) };
}
[[nodiscard]] static ClientSocket create_client(
AddressFamily address_family,
std::string const& host,
std::uint16_t port,
[[maybe_unused]] Sockets const& key = instance()
);
private:
[[nodiscard]] static Sockets const& instance();
};
} // namespace c2k