Merge tag '12.2' into 12
This commit is contained in:
@@ -217,6 +217,8 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
|
||||
*/
|
||||
bool NetworkTCPSocketHandler::CanSendReceive()
|
||||
{
|
||||
assert(this->sock != INVALID_SOCKET);
|
||||
|
||||
fd_set read_fd, write_fd;
|
||||
struct timeval tv;
|
||||
|
||||
|
||||
@@ -363,7 +363,10 @@ bool TCPConnecter::CheckActivity()
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Check for errors on any of the sockets. */
|
||||
/* If a socket is writeable, it is either in error-state or connected.
|
||||
* Remove all sockets that are in error-state and mark the first that is
|
||||
* not in error-state as the socket we will use for our connection. */
|
||||
SOCKET connected_socket = INVALID_SOCKET;
|
||||
for (auto it = this->sockets.begin(); it != this->sockets.end(); /* nothing */) {
|
||||
NetworkError socket_error = GetSocketError(*it);
|
||||
if (socket_error.HasError()) {
|
||||
@@ -371,34 +374,28 @@ bool TCPConnecter::CheckActivity()
|
||||
closesocket(*it);
|
||||
this->sock_to_address.erase(*it);
|
||||
it = this->sockets.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* In case all sockets had an error, queue a new one. */
|
||||
if (this->sockets.empty()) {
|
||||
if (!this->TryNextAddress()) {
|
||||
/* There were no more addresses to try, so we failed. */
|
||||
this->OnFailure();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* At least one socket is connected. The first one that does is the one
|
||||
* we will be using, and we close all other sockets. */
|
||||
SOCKET connected_socket = INVALID_SOCKET;
|
||||
for (auto it = this->sockets.begin(); it != this->sockets.end(); /* nothing */) {
|
||||
/* No error but writeable means connected. */
|
||||
if (connected_socket == INVALID_SOCKET && FD_ISSET(*it, &write_fd)) {
|
||||
connected_socket = *it;
|
||||
} else {
|
||||
}
|
||||
|
||||
it++;
|
||||
}
|
||||
|
||||
/* All the writable sockets were in error state. So nothing is connected yet. */
|
||||
if (connected_socket == INVALID_SOCKET) return false;
|
||||
|
||||
/* Close all sockets except the one we picked for our connection. */
|
||||
for (auto it = this->sockets.begin(); it != this->sockets.end(); /* nothing */) {
|
||||
if (connected_socket != *it) {
|
||||
closesocket(*it);
|
||||
}
|
||||
this->sock_to_address.erase(*it);
|
||||
it = this->sockets.erase(it);
|
||||
}
|
||||
assert(connected_socket != INVALID_SOCKET);
|
||||
|
||||
Debug(net, 3, "Connected to {}", this->connection_string);
|
||||
if (_debug_net_level >= 5) {
|
||||
@@ -451,6 +448,8 @@ bool TCPServerConnecter::CheckActivity()
|
||||
*/
|
||||
void TCPServerConnecter::SetConnected(SOCKET sock)
|
||||
{
|
||||
assert(sock != INVALID_SOCKET);
|
||||
|
||||
this->socket = sock;
|
||||
this->status = Status::CONNECTED;
|
||||
}
|
||||
|
||||
@@ -566,6 +566,8 @@ void ClientNetworkCoordinatorSocketHandler::ConnectFailure(const std::string &to
|
||||
*/
|
||||
void ClientNetworkCoordinatorSocketHandler::ConnectSuccess(const std::string &token, SOCKET sock, NetworkAddress &address)
|
||||
{
|
||||
assert(sock != INVALID_SOCKET);
|
||||
|
||||
/* Connecter will destroy itself. */
|
||||
this->game_connecter = nullptr;
|
||||
|
||||
|
||||
@@ -2233,7 +2233,6 @@ struct NetworkJoinStatusWindow : Window {
|
||||
{
|
||||
if (StrEmpty(str)) {
|
||||
NetworkDisconnect();
|
||||
ShowNetworkGameWindow();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
{
|
||||
this->handler->connecter = nullptr;
|
||||
|
||||
handler->sock = s;
|
||||
this->handler->sock = s;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user