refactor: add more debug messages for sockets
This commit is contained in:
@@ -25,15 +25,19 @@ bool TCPSocket::Connect(const IPAddress& address, unsigned short port) {
|
|||||||
|
|
||||||
struct addrinfo hints = { 0 }, * result = nullptr;
|
struct addrinfo hints = { 0 }, * result = nullptr;
|
||||||
|
|
||||||
if ((m_Handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
|
if ((m_Handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
|
||||||
|
std::cerr << "Failed to create socket !\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_protocol = IPPROTO_TCP;
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
|
|
||||||
if (getaddrinfo(address.ToString().c_str(), std::to_string(port).c_str(), &hints, &result) != 0)
|
if (getaddrinfo(address.ToString().c_str(), std::to_string(port).c_str(), &hints, &result) != 0) {
|
||||||
|
std::cerr << "Failed to get adress info !\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
struct addrinfo* ptr = nullptr;
|
struct addrinfo* ptr = nullptr;
|
||||||
for (ptr = result; ptr != nullptr; ptr = ptr->ai_next) {
|
for (ptr = result; ptr != nullptr; ptr = ptr->ai_next) {
|
||||||
@@ -46,8 +50,10 @@ bool TCPSocket::Connect(const IPAddress& address, unsigned short port) {
|
|||||||
|
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
|
|
||||||
if (!ptr)
|
if (!ptr) {
|
||||||
|
std::cerr << "Could not find a suitable interface for connecting !\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this->SetStatus(Connected);
|
this->SetStatus(Connected);
|
||||||
m_RemoteIP = address;
|
m_RemoteIP = address;
|
||||||
|
|||||||
Reference in New Issue
Block a user