13 if (port < 1 || port > 65535)
throw ListenerException(
"invalid port: " + std::to_string(port));
15 _fd = socket(AF_INET, SOCK_STREAM, 0);
19 setsockopt(
_fd, SOL_SOCKET, SO_REUSEADDR, &opt,
sizeof(opt));
22 addr.sin_family = AF_INET;
23 addr.sin_addr.s_addr = INADDR_ANY;
24 addr.sin_port = htons(
static_cast<uint16_t
>(port));
26 if (bind(
_fd,
reinterpret_cast<sockaddr*
>(&addr),
sizeof(addr)) < 0) {
32 if (listen(
_fd, SOMAXCONN) < 0) {