mirror of
https://github.com/oatpp/oatpp.git
synced 2025-01-18 16:43:57 +08:00
add error log
This commit is contained in:
parent
eabe287550
commit
7f4306f8ff
@ -172,26 +172,27 @@ oatpp::v_io_handle SimpleTCPConnectionProvider::instantiateServer(){
|
|||||||
|
|
||||||
ret = getaddrinfo(NULL, (const char *) portStr->getData(), &hints, &result);
|
ret = getaddrinfo(NULL, (const char *) portStr->getData(), &hints, &result);
|
||||||
if (ret != 0) {
|
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.");
|
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);
|
serverHandle = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
|
||||||
if (serverHandle < 0) {
|
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");
|
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));
|
ret = setsockopt(serverHandle, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
|
||||||
if(ret < 0) {
|
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);
|
ret = bind(serverHandle, result->ai_addr, (int) result->ai_addrlen);
|
||||||
|
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
::close(serverHandle);
|
::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);
|
ret = listen(serverHandle, 10000);
|
||||||
|
Loading…
Reference in New Issue
Block a user