mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r7825) -Codechange: make NetworkUDPClose close a single UDP socket. Use NetworkUDPStop to close all opened udp sockets (those were called NetworkUDPClose).
This commit is contained in:
parent
ffa7673aaa
commit
72b2b15cbd
@ -18,25 +18,6 @@
|
||||
* @file udp.c Basic functions to receive and send UDP packets.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Send a packet over UDP
|
||||
* @param udp the socket to send over
|
||||
* @param p the packet to send
|
||||
* @param recv the receiver (target) of the packet
|
||||
*/
|
||||
void NetworkSendUDP_Packet(SOCKET udp, Packet *p, struct sockaddr_in *recv)
|
||||
{
|
||||
int res;
|
||||
|
||||
NetworkSend_FillPacketSize(p);
|
||||
|
||||
/* Send the buffer */
|
||||
res = sendto(udp, p->buffer, p->size, 0, (struct sockaddr *)recv, sizeof(*recv));
|
||||
|
||||
/* Check for any errors, but ignore it otherwise */
|
||||
if (res == -1) DEBUG(net, 1, "[udp] sendto failed with: %i", GET_LAST_ERROR());
|
||||
}
|
||||
|
||||
/**
|
||||
* Start listening on the given host and port.
|
||||
* @param udp the place where the (references to the) UDP are stored
|
||||
@ -91,6 +72,38 @@ bool NetworkUDPListen(SOCKET *udp, uint32 host, uint16 port, bool broadcast)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the given UDP socket
|
||||
* @param udp the socket to close
|
||||
*/
|
||||
void NetworkUDPClose(SOCKET *udp)
|
||||
{
|
||||
if (*udp == INVALID_SOCKET) return;
|
||||
|
||||
closesocket(*udp);
|
||||
*udp = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send a packet over UDP
|
||||
* @param udp the socket to send over
|
||||
* @param p the packet to send
|
||||
* @param recv the receiver (target) of the packet
|
||||
*/
|
||||
void NetworkSendUDP_Packet(SOCKET udp, Packet *p, struct sockaddr_in *recv)
|
||||
{
|
||||
int res;
|
||||
|
||||
NetworkSend_FillPacketSize(p);
|
||||
|
||||
/* Send the buffer */
|
||||
res = sendto(udp, p->buffer, p->size, 0, (struct sockaddr *)recv, sizeof(*recv));
|
||||
|
||||
/* Check for any errors, but ignore it otherwise */
|
||||
if (res == -1) DEBUG(net, 1, "[udp] sendto failed with: %i", GET_LAST_ERROR());
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive a packet at UDP level
|
||||
* @param udp the socket to receive the packet on
|
||||
|
@ -11,8 +11,10 @@
|
||||
|
||||
///** Sending/receiving of UDP packets **////
|
||||
|
||||
void NetworkSendUDP_Packet(SOCKET udp, Packet *p, struct sockaddr_in *recv);
|
||||
bool NetworkUDPListen(SOCKET *udp, uint32 host, uint16 port, bool broadcast);
|
||||
void NetworkUDPClose(SOCKET *udp);
|
||||
|
||||
void NetworkSendUDP_Packet(SOCKET udp, Packet *p, struct sockaddr_in *recv);
|
||||
void NetworkUDPReceive(SOCKET udp);
|
||||
|
||||
/**
|
||||
|
@ -833,7 +833,7 @@ static void NetworkClose(void)
|
||||
closesocket(_listensocket);
|
||||
_listensocket = INVALID_SOCKET;
|
||||
DEBUG(net, 1, "Closed listener");
|
||||
NetworkUDPClose();
|
||||
NetworkUDPStop();
|
||||
}
|
||||
}
|
||||
|
||||
@ -949,7 +949,7 @@ bool NetworkClientConnectGame(const char *host, uint16 port)
|
||||
_network_last_port = port;
|
||||
|
||||
NetworkDisconnect();
|
||||
NetworkUDPClose();
|
||||
NetworkUDPStop();
|
||||
NetworkInitialize();
|
||||
|
||||
// Try to connect
|
||||
@ -1426,7 +1426,7 @@ void NetworkStartUp(void)
|
||||
void NetworkShutDown(void)
|
||||
{
|
||||
NetworkDisconnect();
|
||||
NetworkUDPClose();
|
||||
NetworkUDPStop();
|
||||
|
||||
DEBUG(net, 3, "[core] shutting down network");
|
||||
|
||||
|
@ -179,7 +179,7 @@ void UpdateNetworkGameWindow(bool unselect);
|
||||
void CheckMinPlayers(void);
|
||||
|
||||
void NetworkStartUp(void);
|
||||
void NetworkUDPClose(void);
|
||||
void NetworkUDPStop(void);
|
||||
void NetworkShutDown(void);
|
||||
void NetworkGameLoop(void);
|
||||
void NetworkUDPGameLoop(void);
|
||||
|
@ -446,30 +446,19 @@ void NetworkHandleUDPPacket(SOCKET udp, Packet *p, struct sockaddr_in *client_ad
|
||||
|
||||
|
||||
// Close UDP connection
|
||||
void NetworkUDPClose(void)
|
||||
void NetworkUDPStop(void)
|
||||
{
|
||||
DEBUG(net, 1, "[udp] closed listeners");
|
||||
|
||||
if (_network_udp_server) {
|
||||
if (_udp_server_socket != INVALID_SOCKET) {
|
||||
closesocket(_udp_server_socket);
|
||||
_udp_server_socket = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if (_udp_master_socket != INVALID_SOCKET) {
|
||||
closesocket(_udp_master_socket);
|
||||
_udp_master_socket = INVALID_SOCKET;
|
||||
NetworkUDPClose(&_udp_server_socket);
|
||||
NetworkUDPClose(&_udp_master_socket);
|
||||
} else {
|
||||
NetworkUDPClose(&_udp_client_socket);
|
||||
}
|
||||
|
||||
_network_udp_server = false;
|
||||
_network_udp_broadcast = 0;
|
||||
} else {
|
||||
if (_udp_client_socket != INVALID_SOCKET) {
|
||||
closesocket(_udp_client_socket);
|
||||
_udp_client_socket = INVALID_SOCKET;
|
||||
}
|
||||
_network_udp_broadcast = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast to all ips
|
||||
|
@ -747,10 +747,10 @@ void SwitchMode(int new_mode)
|
||||
if (_networking) {
|
||||
if (_network_server && (new_mode == SM_LOAD || new_mode == SM_NEWGAME)) {
|
||||
NetworkReboot();
|
||||
NetworkUDPClose();
|
||||
NetworkUDPStop();
|
||||
} else {
|
||||
NetworkDisconnect();
|
||||
NetworkUDPClose();
|
||||
NetworkUDPStop();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user