Codechange: replace seprintf with C++ style formatting
This commit is contained in:
@@ -215,8 +215,7 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *
|
||||
hints.ai_socktype = socktype;
|
||||
|
||||
/* The port needs to be a string. Six is enough to contain all characters + '\0'. */
|
||||
char port_name[6];
|
||||
seprintf(port_name, lastof(port_name), "%u", this->GetPort());
|
||||
std::string port_name = std::to_string(this->GetPort());
|
||||
|
||||
bool reset_hostname = false;
|
||||
/* Setting both hostname to nullptr and port to 0 is not allowed.
|
||||
@@ -231,7 +230,7 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *
|
||||
|
||||
static bool _resolve_timeout_error_message_shown = false;
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
int e = getaddrinfo(this->hostname.empty() ? nullptr : this->hostname.c_str(), port_name, &hints, &ai);
|
||||
int e = getaddrinfo(this->hostname.empty() ? nullptr : this->hostname.c_str(), port_name.c_str(), &hints, &ai);
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
std::chrono::seconds duration = std::chrono::duration_cast<std::chrono::seconds>(end - start);
|
||||
if (!_resolve_timeout_error_message_shown && duration >= std::chrono::seconds(5)) {
|
||||
|
@@ -83,9 +83,10 @@ const std::string &NetworkError::AsString() const
|
||||
char buffer[512];
|
||||
if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, this->error,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), NULL) == 0) {
|
||||
seprintf(buffer, lastof(buffer), "Unknown error %d", this->error);
|
||||
this->message.assign(fmt::format("Unknown error {}", this->error));
|
||||
} else {
|
||||
this->message.assign(buffer);
|
||||
}
|
||||
this->message.assign(buffer);
|
||||
#else
|
||||
/* Make strerror thread safe by locking access to it. There is a thread safe strerror_r, however
|
||||
* the non-POSIX variant is available due to defining _GNU_SOURCE meaning it is not portable.
|
||||
|
@@ -233,14 +233,13 @@ void TCPConnecter::Resolve()
|
||||
hints.ai_flags = AI_ADDRCONFIG;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
char port_name[6];
|
||||
seprintf(port_name, lastof(port_name), "%u", address.GetPort());
|
||||
std::string port_name = std::to_string(address.GetPort());
|
||||
|
||||
static bool getaddrinfo_timeout_error_shown = false;
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
|
||||
addrinfo *ai;
|
||||
int error = getaddrinfo(address.GetHostname().c_str(), port_name, &hints, &ai);
|
||||
int error = getaddrinfo(address.GetHostname().c_str(), port_name.c_str(), &hints, &ai);
|
||||
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::seconds>(end - start);
|
||||
|
Reference in New Issue
Block a user