我有一个非常简单的包装器boost :: asio套接字发送多播消息:
// header class MulticastSender { public: /// Constructor /// @param ip - The multicast address to broadcast on /// @param port - The multicast port to broadcast on MulticastSender(const String& ip,const UInt16 port); /// Sends a multicast message /// @param msg - The message to send /// @param size - The size of the message (in bytes) /// @return number of bytes sent size_t send(const void* msg,const size_t size); private: boost::asio::io_service m_service; boost::asio::ip::udp::endpoint m_endpoint; boost::asio::ip::udp::socket m_socket; }; // implementation inline MulticastSender::MulticastSender(const String& ip,const UInt16 port) : m_endpoint(boost::asio::ip::address_v4::from_string(ip),port),m_socket(m_service,m_endpoint.protocol()) { m_socket.set_option(boost::asio::socket_base::send_buffer_size(8 * 1024 * 1024)); m_socket.set_option(boost::asio::socket_base::broadcast(true)); m_socket.set_option(boost::asio::socket_base::reuse_address(true)); } inline size_t MulticastSender::send(const void* msg,const size_t size) { try { return m_socket.send_to(boost::asio::buffer(msg,size),m_endpoint); } catch (const std::exception& e) { setError(e.what()); } return 0; } // read and send a message MulticastSender sender(ip,port); while(readFile(&msg)) sender.send(&msg,sizeof(msg));
当使用Visual Studio 2013在Windows 7上编译时,我在Ubuntu 14.04〜100 MB / s时可以获得〜11 MB / s的吞吐量.我添加了计时器,并且能够验证发送(…)方法是罪魁祸首.
我尝试使用和不启用防病毒功能,并尝试禁用其他几项服务,没有运气.有些我无法通过计算机上的权限禁用,如防火墙.
我假设Windows上运行的服务是干扰的,或者我的实现缺少在Windows而不是Linux上影响应用程序的一些.
任何关于可能正在考虑的想法将不胜感激