From 7f4306f8ffa7c6d718822bd8380e327df7b31d85 Mon Sep 17 00:00:00 2001 From: Yhz Date: Wed, 1 Apr 2020 22:12:08 +0800 Subject: [PATCH] add error log --- src/oatpp/network/server/SimpleTCPConnectionProvider.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/oatpp/network/server/SimpleTCPConnectionProvider.cpp b/src/oatpp/network/server/SimpleTCPConnectionProvider.cpp index 076019b9..256d9070 100644 --- a/src/oatpp/network/server/SimpleTCPConnectionProvider.cpp +++ b/src/oatpp/network/server/SimpleTCPConnectionProvider.cpp @@ -172,26 +172,27 @@ oatpp::v_io_handle SimpleTCPConnectionProvider::instantiateServer(){ ret = getaddrinfo(NULL, (const char *) portStr->getData(), &hints, &result); if (ret != 0) { - OATPP_LOGE("[oatpp::network::server::SimpleTCPConnectionProvider::instantiateServer()]", "Error. Call to getaddrinfo() failed with result=%d", ret); + OATPP_LOGE("[oatpp::network::server::SimpleTCPConnectionProvider::instantiateServer()]", "Error. Call to getaddrinfo() failed with result=%d: %s", ret, strerror(errno)); throw std::runtime_error("[oatpp::network::server::SimpleTCPConnectionProvider::instantiateServer()]: Error. Call to getaddrinfo() failed."); } serverHandle = socket(result->ai_family, result->ai_socktype, result->ai_protocol); if (serverHandle < 0) { - OATPP_LOGE("[oatpp::network::server::SimpleTCPConnectionProvider::instantiateServer()]", "Error. Couldn't open a socket"); + OATPP_LOGE("[oatpp::network::server::SimpleTCPConnectionProvider::instantiateServer()]", "Error. Couldn't open a socket: %s", strerror(errno)); throw std::runtime_error("[oatpp::network::server::SimpleTCPConnectionProvider::instantiateServer()]: Error. Couldn't open a socket"); } ret = setsockopt(serverHandle, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); if(ret < 0) { - OATPP_LOGD("[oatpp::network::server::SimpleTCPConnectionProvider::instantiateServer()]", "Warning. Failed to set %s for accepting socket", "SO_REUSEADDR"); + OATPP_LOGE("[oatpp::network::server::SimpleTCPConnectionProvider::instantiateServer()]", "Warning. Failed to set %s for accepting socket: %s", "SO_REUSEADDR", strerror(errno)); } ret = bind(serverHandle, result->ai_addr, (int) result->ai_addrlen); if(ret != 0) { ::close(serverHandle); - throw std::runtime_error("[oatpp::network::server::SimpleTCPConnectionProvider::instantiateServer()]: Error. Can't bind to address."); + OATPP_LOGE("[oatpp::network::server::SimpleTCPConnectionProvider::instantiateServer()]", "Error. Failed to bind port %d: %s", m_port, strerror(errno)); + throw std::runtime_error("[oatpp::network::server::SimpleTCPConnectionProvider::instantiateServer()]: Error. Can't bind to address: %s"); } ret = listen(serverHandle, 10000);