boost-asio

UDP socket network disconnect behavior on Windows-Linux-Mac

戏子无情 提交于 2019-12-11 03:25:39
问题 I made an application using boost.Asio using UDP multicast. I don't think the question is really specific to boost.Asio but to sockets programming in general, since boost.Asio's network facilities are mostly wrappers to socket functions. I constructed the application based on the multicast examples ( http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/example/multicast/receiver.cpp and ~/sender.cpp) and I deployed it on several machines running on Windows, Linux and a Mac with OSX

efficient copy of data from boost::asio::streambuf to std::string

那年仲夏 提交于 2019-12-11 03:17:53
问题 I need to copy the content of a (boost::asio::)streambuf to an std::string. The following code works, but I think that there's an unnecessary copy between _msg and the temporary std::string: Msg (boost::asio::streambuf & sb, size_t bytes_transferred) : _nBytesInMsg (bytes_transferred) { boost::asio::streambuf::const_buffers_type buf = sb.data(); _msg = std::string( boost::asio::buffers_begin(buf), boost::asio::buffers_begin(buf) + _nBytesInMsg); } I tried replacing with the following: _msg

make_shared doesn't play along with enable_shared_from_this?

白昼怎懂夜的黑 提交于 2019-12-11 02:34:11
问题 Consider the following two code snippets, The first one: #include "pch.h" #include <memory> #include <boost/asio.hpp> using boost::asio::ip::tcp; class tcp_connection : public std::enable_shared_from_this<tcp_connection> { public: typedef std::shared_ptr<tcp_connection> pointer; static pointer create(boost::asio::io_service& io_service) { return pointer(new tcp_connection(io_service)); //second example only differs by replacing the above line with the below one //return std::make_shared<tcp

Do I need to implement blocking when using boost::asio?

点点圈 提交于 2019-12-11 02:24:38
问题 My question is, if I run io_service::run () on multiple threads, do I need to implement blocking on these asynchronous functions? example: int i = 0; int j = 0; void test_timer(boost::system::error_code ec) { //I need to lock up here ? if (i++ == 10) { j = i * 10; } timer.expires_at(timer.expires_at() + boost::posix_time::milliseconds(500)); timer.async_wait(&test_timer); } void threadMain() { io_service.run(); } int main() { boost::thread_group workers; timer.async_wait(&test_timer); for

Boost::asio linking; identifier not found; C++

随声附和 提交于 2019-12-11 02:22:54
问题 I googled the error lines of my problem and got hardly any hits and I don't speak russian. I also found this, but it doesn't seem to help me. This is my code #include <iostream> #include <boost/asio.hpp> #include <boost/date_time/posix_time/posix_time.hpp> int main() { boost::asio::io_service io; boost::asio::deadline_timer t(io,boost::posix_time::seconds(5)); t.wait(); std::cout << "Hello World" << std::endl; return 0; } These be my error messages: 1>------ Build started: Project:

boost::asio sending data faster than receiving over TCP. Or how to disable buffering

放肆的年华 提交于 2019-12-11 02:07:24
问题 I have created a client/server program, the client starts an instance of Writer class and the server starts an instance of Reader class. Writer will then write a DATA_SIZE bytes of data asynchronously to the Reader every USLEEP mili seconds. Every successive async_write request by the Writer is done only if the "on write" handler from the previous request had been called. The problem is, If the Writer (client) is writing more data into the socket than the Reader (server) is capable of

boost::property_tree::read_xml segfaults in an asio handler spawned using boost::asio::spawn

三世轮回 提交于 2019-12-11 01:59:37
问题 The following code crashes with a seg fault at boost::property_tree::read_xml() call. This happens only if it's called inside of an io_service handler spawned using boost::asio::spawn(). If the handler is just posted, it works ok. Is there a fix or workaround for this? (boost 1.61) #include <boost/asio/spawn.hpp> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <iostream> #include <sstream> #include <thread> void process() { std::cerr << "start"<

Boost asio with Qt

烈酒焚心 提交于 2019-12-11 00:34:46
问题 I am trying to use boost::asio async client example with a simple Qt GUI like: A little snippet from my app: The button click SLOT: void RestWidget::restGetCall() { networkService ntwkSer("www.boost.org","80"); connect(&ntwkSer, SIGNAL(responseReady(std::string)), this, SLOT(showResponse(std::string))); ntwkSer.get("/LICENSE_1_0.txt"); } The networkService class is just a wrapper of the above linked boost sample code.Its derived from QObject class for signal,slot mechanism. void

Understanding issue with shared pointers (Lifetime, passing as parameter)

て烟熏妆下的殇ゞ 提交于 2019-12-10 23:33:09
问题 I tried to start with the boost asio chat example and derive an own networking program. Unfortunately I have some problem understanding what really happens. I tried to reduce my program to an absolute minimum. A server class waits for incoming connections and creates a session object to handle the connection. This is the code of the server: #include <cstdint> #include <iostream> #include <sstream> #include <memory> #include <vector> #include <boost/asio.hpp> #include <boost/bind.hpp> class

How to send an std::vector of unsigned char over an UDP socket using boost asio?

天涯浪子 提交于 2019-12-10 23:29:14
问题 This is a extension to my previous question here with a " minimum viable example " of the code. I have developed a UDPClient & UDPServer app as below. These apps are very much similar to the boost official udp client & boost official udp server: UDPClient.cpp #include <iostream> #include <algorithm> #include <boost/asio.hpp> using boost::asio::ip::udp; struct Person { char name[1024]; int age; }; int main(int argc, char* argv[]) { // Turn this variable TRUE on to send structs of "Person" bool