MCPcopy Create free account
hub / github.com/Tablecruncher/tablecruncher / bind_internal

Method bind_internal

external/httplib.h:6681–6707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6679}
6680
6681inline int Server::bind_internal(const std::string &host, int port,
6682 int socket_flags) {
6683 if (is_decommisioned) { return -1; }
6684
6685 if (!is_valid()) { return -1; }
6686
6687 svr_sock_ = create_server_socket(host, port, socket_flags, socket_options_);
6688 if (svr_sock_ == INVALID_SOCKET) { return -1; }
6689
6690 if (port == 0) {
6691 struct sockaddr_storage addr;
6692 socklen_t addr_len = sizeof(addr);
6693 if (getsockname(svr_sock_, reinterpret_cast<struct sockaddr *>(&addr),
6694 &addr_len) == -1) {
6695 return -1;
6696 }
6697 if (addr.ss_family == AF_INET) {
6698 return ntohs(reinterpret_cast<struct sockaddr_in *>(&addr)->sin_port);
6699 } else if (addr.ss_family == AF_INET6) {
6700 return ntohs(reinterpret_cast<struct sockaddr_in6 *>(&addr)->sin6_port);
6701 } else {
6702 return -1;
6703 }
6704 } else {
6705 return port;
6706 }
6707}
6708
6709inline bool Server::listen_internal() {
6710 if (is_decommisioned) { return false; }

Callers

nothing calls this directly

Calls 1

is_validFunction · 0.50

Tested by

no test coverage detected