(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:
rubidium
2007-01-04 18:10:40 +00:00
parent 2fda7e6c10
commit ae9750e69b
6 changed files with 48 additions and 44 deletions

View File

@@ -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