From 72b2b15cbd2e83a91dde5e8ee0e12ec412af7c0b Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 4 Jan 2007 18:10:40 +0000 Subject: (svn r7825) -Codechange: make NetworkUDPClose close a single UDP socket. Use NetworkUDPStop to close all opened udp sockets (those were called NetworkUDPClose). --- src/network/core/udp.c | 51 +++++++++++++++++++++++++++++++------------------- src/network/core/udp.h | 4 +++- 2 files changed, 35 insertions(+), 20 deletions(-) (limited to 'src/network/core') 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 @@ -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 diff --git a/src/network/core/udp.h b/src/network/core/udp.h index f927c289c..ab7682836 100644 --- a/src/network/core/udp.h +++ b/src/network/core/udp.h @@ -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); /** -- cgit v1.2.3-70-g09d2