@@ -56,7 +56,7 @@ void WinSocket::listenToConnections()
56
56
}
57
57
}
58
58
59
- void WinSocket::acceptConnection (SOCKET &client_socket, void *client_address)
59
+ bool WinSocket::acceptConnection (SOCKET &client_socket, void *client_address)
60
60
{
61
61
struct sockaddr_storage client_addr_storage;
62
62
int client_addr_size = sizeof (client_addr_storage);
@@ -68,22 +68,19 @@ void WinSocket::acceptConnection(SOCKET &client_socket, void *client_address)
68
68
throw SocketAcceptException (" error accepting connections" , WSAGetLastError ());
69
69
}
70
70
71
- // Assuming client_address is meant to store the result
72
71
if (client_address != nullptr )
73
72
{
74
73
std::memcpy (client_address, &client_addr_storage, client_addr_size);
75
74
}
76
75
77
- char ip_str[INET6_ADDRSTRLEN] = {0 }; // Large enough for both IPv4 and IPv6
76
+ char ip_str[INET6_ADDRSTRLEN] = {0 };
78
77
if (client_addr_storage.ss_family == AF_INET)
79
78
{
80
- // IPv4
81
79
struct sockaddr_in *addr_in = (struct sockaddr_in *)&client_addr_storage;
82
80
inet_ntop (AF_INET, &addr_in->sin_addr , ip_str, INET_ADDRSTRLEN);
83
81
}
84
82
else if (client_addr_storage.ss_family == AF_INET6)
85
83
{
86
- // IPv6
87
84
struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)&client_addr_storage;
88
85
inet_ntop (AF_INET6, &addr_in6->sin6_addr , ip_str, INET6_ADDRSTRLEN);
89
86
}
@@ -94,9 +91,13 @@ void WinSocket::acceptConnection(SOCKET &client_socket, void *client_address)
94
91
{
95
92
if (this ->client_ip == it)
96
93
{
97
- throw IPBlackListedException () ;
94
+ return false ;
98
95
}
99
96
}
97
+
98
+ this ->client_sockets .push_back (client_socket);
99
+
100
+ return true ;
100
101
}
101
102
102
103
ssize_t WinSocket::receiveData (SOCKET client_socket, char *buffer, unsigned int buffer_size)
0 commit comments