diff options
author | rubidium <rubidium@openttd.org> | 2007-01-04 18:10:40 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-01-04 18:10:40 +0000 |
commit | ae9750e69bb415d1d41ab63ecda566d6c61f2b47 (patch) | |
tree | ea1b145a0458b56d9a82668e8520cfe206388fb5 /src/network/core/udp.c | |
parent | 2fda7e6c10551ad6a1573b8b78aa2d9f17620e88 (diff) | |
download | openttd-ae9750e69bb415d1d41ab63ecda566d6c61f2b47.tar.xz |
(svn r7825) -Codechange: make NetworkUDPClose close a single UDP socket. Use NetworkUDPStop to close all opened udp sockets (those were called NetworkUDPClose).
Diffstat (limited to 'src/network/core/udp.c')
-rw-r--r-- | src/network/core/udp.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/src/network/core/udp.c b/src/network/core/udp.c index 2ae14d5fa..d688233b0 100644 --- a/src/network/core/udp.c +++ b/src/network/core/udp.c @@ -19,25 +19,6 @@ */ /** - * 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 * @param host the host (ip) to listen on @@ -92,6 +73,38 @@ bool NetworkUDPListen(SOCKET *udp, uint32 host, uint16 port, bool broadcast) } /** + * 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 */ |