ServerHost HostBuilder::buildServer() { mySocket = WinSocketBuilder::newInstance() .setAddressFamily(socketAddress.sin_family) .setSocketType(socketType) .setProtocol(protocolType) .build(); return ServerHost(mySocket,socketAddress,file); }
// Returns only the port part (e.g. 80) as an int. static int ServerPort() { if (!IsEnabled()) return 0; std::string host = ServerHost(); size_t offset = ServerHostnameLength(); // If there's no port, use the default one. if (offset == host.npos) return DEFAULT_PORT; // Skip the colon. std::string port = host.substr(offset + 1); return atoi(port.c_str()); }
// Returns only the hostname part (e.g. "report.ppsspp.org".) static const char *ServerHostname() { if (!IsEnabled()) return NULL; std::string host = ServerHost(); size_t length = ServerHostnameLength(); // This means there's no port number - it's already the hostname. if (length == host.npos) lastHostname = host; else lastHostname = host.substr(0, length); return lastHostname.c_str(); }
// Returns the length of the hostname part (e.g. before the :80.) static size_t ServerHostnameLength() { if (!IsEnabled()) return g_Config.sReportHost.npos; // IPv6 literal? std::string hostString = ServerHost(); if (hostString[0] == '[') { size_t length = hostString.find("]:"); if (length != hostString.npos) ++length; return length; } else return hostString.find(':'); }