| 139 int decodedLength = sizeof decodedPacket; |
139 int decodedLength = sizeof decodedPacket; |
| 140 HUFFMAN_Decode (reinterpret_cast<unsigned char*> (HuffmanBuffer), |
140 HUFFMAN_Decode (reinterpret_cast<unsigned char*> (HuffmanBuffer), |
| 141 decodedPacket, length, &decodedLength); |
141 decodedPacket, length, &decodedLength); |
| 142 datagram.address.host = ntohl (claddr.sin_addr.s_addr); |
142 datagram.address.host = ntohl (claddr.sin_addr.s_addr); |
| 143 datagram.address.port = ntohs (claddr.sin_port); |
143 datagram.address.port = ntohs (claddr.sin_port); |
| 144 datagram.message = Bytestream (decodedPacket, decodedLength); |
144 datagram.message = ByteArray(decodedPacket, decodedLength); |
| 145 return true; |
145 return true; |
| 146 } |
146 } |
| 147 |
147 |
| 148 // ------------------------------------------------------------------------------------------------- |
148 // ------------------------------------------------------------------------------------------------- |
| 149 // |
149 // |
| 150 bool UDPSocket::send (const IPAddress& address, const Bytestream& data) |
150 bool UDPSocket::send (const IPAddress& address, const ByteArray& data) |
| 151 { |
151 { |
| 152 int encodedlength = sizeof HuffmanBuffer; |
152 int encodedlength = sizeof HuffmanBuffer; |
| 153 HUFFMAN_Encode (data.data(), reinterpret_cast<unsigned char*> (HuffmanBuffer), |
153 HUFFMAN_Encode (data.data(), reinterpret_cast<unsigned char*> (HuffmanBuffer), data.size(), &encodedlength); |
| 154 data.written_length(), &encodedlength); |
|
| 155 sockaddr_in claddr = address.to_sockaddr_in(); |
154 sockaddr_in claddr = address.to_sockaddr_in(); |
| 156 int res = ::sendto (m_socket, HuffmanBuffer, encodedlength, 0, |
155 int res = ::sendto (m_socket, HuffmanBuffer, encodedlength, 0, |
| 157 reinterpret_cast<sockaddr*> (&claddr), sizeof claddr); |
156 reinterpret_cast<sockaddr*> (&claddr), sizeof claddr); |
| 158 |
157 |
| 159 if (res == -1) |
158 if (res == -1) |