diff -r a76af67a3a4b -r 7b156b764d11 sources/network/udpsocket.cpp --- a/sources/network/udpsocket.cpp Sat Jan 09 02:35:00 2016 +0200 +++ b/sources/network/udpsocket.cpp Sat Jan 09 17:41:21 2016 +0200 @@ -33,19 +33,21 @@ #ifndef _WIN32 # include # include +# include +# include #else # include # include #endif #include -#include #include #include -#include #include "../huffman/huffman.h" -static char g_huffmanBuffer[131072]; +BEGIN_ZFC_NAMESPACE + +char UDPSocket::HuffmanBuffer[131072]; // ----------------------------------------------------------------------------- // @@ -56,7 +58,11 @@ // UDPSocket::~UDPSocket() { +#ifdef _WIN32 + closesocket (m_socket); +#else close (m_socket); +#endif } // ------------------------------------------------------------------------------------------------- @@ -89,8 +95,7 @@ // ------------------------------------------------------------------------------------------------- // -METHOD -UDPSocket::bind (unsigned short port) -> bool +bool UDPSocket::bind (unsigned short port) { sockaddr_in svaddr; memset (&svaddr, 0, sizeof svaddr); @@ -113,7 +118,7 @@ { sockaddr_in claddr; socklen_t socklen = sizeof claddr; - int length = ::recvfrom (m_socket, g_huffmanBuffer, sizeof g_huffmanBuffer, 0, + int length = ::recvfrom (m_socket, HuffmanBuffer, sizeof HuffmanBuffer, 0, reinterpret_cast (&claddr), &socklen); if (length == -1) @@ -126,7 +131,7 @@ unsigned char decodedPacket[MAX_DATAGRAM_LENGTH]; int decodedLength = sizeof decodedPacket; - HUFFMAN_Decode (reinterpret_cast (g_huffmanBuffer), + HUFFMAN_Decode (reinterpret_cast (HuffmanBuffer), decodedPacket, length, &decodedLength); datagram.from.host = ntohl (claddr.sin_addr.s_addr); datagram.from.port = ntohs (claddr.sin_port); @@ -136,14 +141,13 @@ // ------------------------------------------------------------------------------------------------- // -METHOD -UDPSocket::send (const IPAddress& address, const Bytestream& data) -> bool +bool UDPSocket::send (const IPAddress& address, const Bytestream& data) { - int encodedlength = sizeof g_huffmanBuffer; - HUFFMAN_Encode (data.data(), reinterpret_cast (g_huffmanBuffer), + int encodedlength = sizeof HuffmanBuffer; + HUFFMAN_Encode (data.data(), reinterpret_cast (HuffmanBuffer), data.written_length(), &encodedlength); sockaddr_in claddr = address.to_sockaddr_in(); - int res = ::sendto (m_socket, g_huffmanBuffer, encodedlength, 0, + int res = ::sendto (m_socket, HuffmanBuffer, encodedlength, 0, reinterpret_cast (&claddr), sizeof claddr); if (res == -1) @@ -154,3 +158,5 @@ return true; } + +END_ZFC_NAMESPACE \ No newline at end of file