mirror of https://github.com/OpenTTD/OpenTTD
(svn r22068) -Codechange/Fix: return "connection lost" instead of "okay" when SendPackets closed the connection
parent
92d0d6d10b
commit
adfd648031
|
@ -90,14 +90,14 @@ void NetworkTCPSocketHandler::SendPacket(Packet *packet)
|
||||||
* @return \c true if a (part of a) packet could be sent and
|
* @return \c true if a (part of a) packet could be sent and
|
||||||
* the connection is not closed yet.
|
* the connection is not closed yet.
|
||||||
*/
|
*/
|
||||||
bool NetworkTCPSocketHandler::SendPackets(bool closing_down)
|
SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down)
|
||||||
{
|
{
|
||||||
ssize_t res;
|
ssize_t res;
|
||||||
Packet *p;
|
Packet *p;
|
||||||
|
|
||||||
/* We can not write to this socket!! */
|
/* We can not write to this socket!! */
|
||||||
if (!this->writable) return false;
|
if (!this->writable) return SPS_NONE_SENT;
|
||||||
if (!this->IsConnected()) return false;
|
if (!this->IsConnected()) return SPS_CLOSED;
|
||||||
|
|
||||||
p = this->packet_queue;
|
p = this->packet_queue;
|
||||||
while (p != NULL) {
|
while (p != NULL) {
|
||||||
|
@ -110,14 +110,14 @@ bool NetworkTCPSocketHandler::SendPackets(bool closing_down)
|
||||||
DEBUG(net, 0, "send failed with error %d", err);
|
DEBUG(net, 0, "send failed with error %d", err);
|
||||||
this->CloseConnection();
|
this->CloseConnection();
|
||||||
}
|
}
|
||||||
return false;
|
return SPS_CLOSED;
|
||||||
}
|
}
|
||||||
return true;
|
return SPS_PARTLY_SENT;
|
||||||
}
|
}
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
/* Client/server has left us :( */
|
/* Client/server has left us :( */
|
||||||
if (!closing_down) this->CloseConnection();
|
if (!closing_down) this->CloseConnection();
|
||||||
return false;
|
return SPS_CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
p->pos += res;
|
p->pos += res;
|
||||||
|
@ -129,11 +129,11 @@ bool NetworkTCPSocketHandler::SendPackets(bool closing_down)
|
||||||
delete p;
|
delete p;
|
||||||
p = this->packet_queue;
|
p = this->packet_queue;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return SPS_PARTLY_SENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return SPS_ALL_SENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,11 +216,6 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkTCPSocketHandler::IsPacketQueueEmpty()
|
|
||||||
{
|
|
||||||
return this->packet_queue == NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether this socket can send or receive something.
|
* Check whether this socket can send or receive something.
|
||||||
* @return \c true when there is something to receive.
|
* @return \c true when there is something to receive.
|
||||||
|
|
|
@ -19,6 +19,14 @@
|
||||||
|
|
||||||
#ifdef ENABLE_NETWORK
|
#ifdef ENABLE_NETWORK
|
||||||
|
|
||||||
|
/** The states of sending the packets. */
|
||||||
|
enum SendPacketsState {
|
||||||
|
SPS_CLOSED, ///< The connection got closed.
|
||||||
|
SPS_NONE_SENT, ///< The buffer is still full, so no (parts of) packets could be sent.
|
||||||
|
SPS_PARTLY_SENT, ///< The packets are partly sent; there are more packets to be sent in the queue.
|
||||||
|
SPS_ALL_SENT, ///< All packets in the queue are sent.
|
||||||
|
};
|
||||||
|
|
||||||
/** Base socket handler for all TCP sockets */
|
/** Base socket handler for all TCP sockets */
|
||||||
class NetworkTCPSocketHandler : public NetworkSocketHandler {
|
class NetworkTCPSocketHandler : public NetworkSocketHandler {
|
||||||
private:
|
private:
|
||||||
|
@ -36,8 +44,7 @@ public:
|
||||||
|
|
||||||
virtual NetworkRecvStatus CloseConnection(bool error = true);
|
virtual NetworkRecvStatus CloseConnection(bool error = true);
|
||||||
virtual void SendPacket(Packet *packet);
|
virtual void SendPacket(Packet *packet);
|
||||||
bool SendPackets(bool closing_down = false);
|
SendPacketsState SendPackets(bool closing_down = false);
|
||||||
bool IsPacketQueueEmpty();
|
|
||||||
|
|
||||||
virtual Packet *ReceivePacket();
|
virtual Packet *ReceivePacket();
|
||||||
|
|
||||||
|
|
|
@ -573,13 +573,23 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
|
||||||
|
|
||||||
if (this->savegame_mutex != NULL) this->savegame_mutex->EndCritical();
|
if (this->savegame_mutex != NULL) this->savegame_mutex->EndCritical();
|
||||||
|
|
||||||
/* Send all packets (forced) and check if we have send it all */
|
switch (this->SendPackets()) {
|
||||||
if (this->SendPackets() && this->IsPacketQueueEmpty()) {
|
case SPS_CLOSED:
|
||||||
/* All are sent, increase the sent_packets */
|
return NETWORK_RECV_STATUS_CONN_LOST;
|
||||||
if (this->savegame_packets != NULL) sent_packets *= 2;
|
|
||||||
} else {
|
case SPS_ALL_SENT:
|
||||||
/* Not everything is sent, decrease the sent_packets */
|
/* All are sent, increase the sent_packets */
|
||||||
if (sent_packets > 1) sent_packets /= 2;
|
if (this->savegame_packets != NULL) sent_packets *= 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SPS_PARTLY_SENT:
|
||||||
|
/* Only a part is sent; leave the transmission state. */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SPS_NONE_SENT:
|
||||||
|
/* Not everything is sent, decrease the sent_packets */
|
||||||
|
if (sent_packets > 1) sent_packets /= 2;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
|
|
Loading…
Reference in New Issue