udpsender.h

00001 // Copyright (C) 2008,2009,2010 by Philipp Münzel. All rights reserved.
00002 // Released under the terms of the license described in license.txt
00003 
00004 #ifndef UDPSENDER_H
00005 #define UDPSENDER_H
00006 
00007 #include "dllexport.h"
00008 
00009 #include <sstream>
00010 #include <string>
00011 #include <boost/asio.hpp>
00012 #include <boost/bind.hpp>
00013 
00014 namespace SCS {
00015 
00022 class DLL_PUBLIC UDPSender
00023 {
00024 public:
00025 
00032     UDPSender(boost::asio::io_service& io_service,
00033               const boost::asio::ip::address& ip_address,
00034               short port,
00035               bool disable_loopback = false);
00036 
00040     ~UDPSender() {}
00041 
00046     void write(const void* data, size_t bytes);
00047 
00048 
00049 private:
00050 
00051     typedef boost::asio::ip::udp::endpoint UDPEndpoint;
00052     typedef boost::asio::ip::udp::socket UDPSocket;
00053 
00060     void handle_send_to(size_t correct_size,
00061                         const boost::system::error_code& error,
00062                         size_t bytes_written);
00063 
00064     void resetFallback(const boost::system::error_code& error);
00065 
00066     UDPEndpoint m_endpoint;
00067 
00068     UDPSocket m_socket;
00069 
00070     int m_multicast_port;
00071 
00072     bool m_fallback_loopback_active;
00073 
00074     int m_fallback_fail_counter;
00075 
00076     boost::asio::deadline_timer m_fallback_reset_timer;
00077 };
00078 
00079 }
00080 
00081 #endif // UDPSENDER_H