Add missing cstring include for strerror

This commit is contained in:
louiz’
2016-11-11 03:03:42 +01:00
parent 0c8adc85f7
commit ed7e66471f
@@ -5,6 +5,7 @@
#include <logger/logger.hpp> #include <logger/logger.hpp>
#include <cstring>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
@@ -27,7 +28,7 @@ void TCPClientSocketHandler::init_socket(const struct addrinfo* rp)
if (this->socket != -1) if (this->socket != -1)
::close(this->socket); ::close(this->socket);
if ((this->socket = ::socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) == -1) if ((this->socket = ::socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) == -1)
throw std::runtime_error("Could not create socket: "s + strerror(errno)); throw std::runtime_error("Could not create socket: "s + std::strerror(errno));
// Bind the socket to a specific address, if specified // Bind the socket to a specific address, if specified
if (!this->bind_addr.empty()) if (!this->bind_addr.empty())
{ {
@@ -66,7 +67,7 @@ void TCPClientSocketHandler::init_socket(const struct addrinfo* rp)
const int existing_flags = ::fcntl(this->socket, F_GETFL, 0); const int existing_flags = ::fcntl(this->socket, F_GETFL, 0);
if ((existing_flags == -1) || if ((existing_flags == -1) ||
(::fcntl(this->socket, F_SETFL, existing_flags | O_NONBLOCK) == -1)) (::fcntl(this->socket, F_SETFL, existing_flags | O_NONBLOCK) == -1))
throw std::runtime_error("Could not initialize socket: "s + strerror(errno)); throw std::runtime_error("Could not initialize socket: "s + std::strerror(errno));
} }
void TCPClientSocketHandler::connect(const std::string& address, const std::string& port, const bool tls) void TCPClientSocketHandler::connect(const std::string& address, const std::string& port, const bool tls)
@@ -176,11 +177,11 @@ void TCPClientSocketHandler::connect(const std::string& address, const std::stri
"connection_timeout"s + std::to_string(this->socket))); "connection_timeout"s + std::to_string(this->socket)));
return ; return ;
} }
log_info("Connection failed:", strerror(errno)); log_info("Connection failed:", std::strerror(errno));
} }
log_error("All connection attempts failed."); log_error("All connection attempts failed.");
this->close(); this->close();
this->on_connection_failed(strerror(errno)); this->on_connection_failed(std::strerror(errno));
return ; return ;
} }