terom@185: #ifndef NETWORK_UDP_HH terom@185: #define NETWORK_UDP_HH terom@185: terom@400: /** terom@400: * @file terom@400: * terom@400: * UDP implementation terom@400: */ terom@400: terom@186: #include "Socket.hh" terom@186: #include "Address.hh" terom@186: #include "Packet.hh" terom@185: terom@286: /** terom@286: * A UDP socket that can send and receive NetworkPackets terom@286: */ terom@185: class NetworkUDP { terom@185: private: terom@286: /** terom@286: * The socket itself terom@286: */ terom@185: NetworkSocket socket; terom@185: terom@185: CL_SlotContainer slots; terom@185: terom@185: public: terom@286: /** terom@286: * Allocate an UDP socket on an ephemeral port (random port chosen by OS) terom@286: */ terom@185: NetworkUDP (void); terom@286: terom@286: /** terom@286: * Allocate an UDP socket on a specific local port/interface terom@286: * terom@286: * @param bind_addr the local address to bind to terom@286: */ terom@381: NetworkUDP (const NetworkEndpoint &bind_addr); terom@185: terom@185: private: terom@286: /** terom@286: * Socket is ready for recv, read as many packets as available, calling sig_packet on each terom@286: */ terom@185: void on_recv (void); terom@286: terom@286: /** terom@286: * The signal called by on_recv terom@286: */ terom@200: CL_Signal_v2 _sig_packet; terom@185: terom@185: public: terom@286: /** terom@286: * Send the given packet on this UDP socket to the given destination address terom@400: * terom@400: * @return true if the packet was passed on to the socket API, false if the socket was busy and the packet was terom@400: * dropped (no chance of it arriving). terom@286: */ terom@202: bool sendto (const NetworkPacketBuffer &packet, const NetworkAddress &dst); terom@185: terom@286: /** terom@286: * Triggered whenever a packet has been received, giving the NetworkPacketInput and the source address terom@286: */ terom@200: CL_Signal_v2& sig_packet (void) { return _sig_packet; } terom@185: }; terom@185: terom@185: #endif /* NETWORK_UDP_HH */