boost-asio

Shared_Ptr of socket creation - what is wrong?

你离开我真会死。 提交于 2020-01-02 15:31:48
问题 So I try: boost::shared_ptr<tcp::socket> socket = boost::make_shared<tcp::socket>(io_service); As described here. But It bring me an error: Compiler tells me that it can not turn ( error C2664: boost::asio::basic_stream_socket<Protocol>::basic_stream_socket( boost::asio::io_­service &)) 'boost::asio::io_service *const ' into 'boost::asio::io_service &' \include\boost\smart_ptr\make_shared.hpp What shall I do? 回答1: You need to pass the io_service as a reference when using make_shared . boost:

Can't implement boost::asio::ssl::stream<boost::asio::ip::tcp::socket> reconnect to server

a 夏天 提交于 2020-01-02 10:09:54
问题 I need to implement a class which handle connect to ssl server. Pretty much based on this. However. it doesn't have reconnect feature. So I modify it like this: boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_; to boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *mpSocket_; and refactor everything related to -> But it leads to errors like this: /usr/include/boost/asio/impl/read.hpp:271: error: request for member 'async_read_some' in '((boost::asio::detail::read_op<boost:

Can't implement boost::asio::ssl::stream<boost::asio::ip::tcp::socket> reconnect to server

﹥>﹥吖頭↗ 提交于 2020-01-02 10:08:21
问题 I need to implement a class which handle connect to ssl server. Pretty much based on this. However. it doesn't have reconnect feature. So I modify it like this: boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_; to boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *mpSocket_; and refactor everything related to -> But it leads to errors like this: /usr/include/boost/asio/impl/read.hpp:271: error: request for member 'async_read_some' in '((boost::asio::detail::read_op<boost:

Boost ASIO UDP client async_receive_from calls handler even when there are no incoming messages

淺唱寂寞╮ 提交于 2020-01-02 09:21:26
问题 I've modified the UDP client code from Boost daytime client tutorial into the following: class UDPClient { public: udp::socket* socket; udp::endpoint* receiver_endpoint; boost::array<char, 1024> recv_buffer; UDPClient(); void do_receive(); void handle_receive(const boost::system::error_code& error, size_t); }; UDPClient::UDPClient() { boost::asio::io_service io_service; udp::resolver resolver(io_service); udp::resolver::query query(udp::v4(), "127.0.0.1", "8888"); receiver_endpoint = new udp:

Fail to listen to UDP Port with boost::asio

非 Y 不嫁゛ 提交于 2020-01-02 06:45:08
问题 I have a server that gathers information and broadcasts some messages across the local network. I'm using boost::asio to broadcast these via UDP on port 8079 and I can verify with WireShark that these packets are actually broadcasted as intended. Now, naturally, I want to follow up with a listener that can react to these messages, but I am struggling to receive anything. My current approach is: boost::asio::io_service io_service; boost::asio::ip::udp::socket socket(io_service); boost::asio:

How copy or reuse boost::asio::streambuf?

喜你入骨 提交于 2020-01-02 05:13:12
问题 I'm implementing http proxy server with some business logic on boost asio. In point (1) boost::asio::streambuf response_ contains http headers and part of http body. After parsing with http_response::parse buffer boost::asio::streambuf response_ is empty. At (2) i check all business logic and read body if there was Content-Length header in headers. Then if response_ data fits specific condtions i want to send the original response_ buffer to another socket (3). The problem is that buffer is

boost::asio hangs in resolver service destructor after throwing out of io_service::run()

前提是你 提交于 2020-01-01 19:08:33
问题 I'm using a fairly simple boost::asio set-up, where I call io_service.run() from the main thread. I have a tcp resolver, and use async resolve to look up an address. When that look-up fails, I throw an exception inside the asynchronous callback. I catch this exception outside the run() call, inside the main function. I then call stop() on my io_service instance (which is a global). However, when main() returns, the program hangs. It turns out to be waiting for an exit_event_ that never comes

boost::asio hangs in resolver service destructor after throwing out of io_service::run()

北城以北 提交于 2020-01-01 19:07:32
问题 I'm using a fairly simple boost::asio set-up, where I call io_service.run() from the main thread. I have a tcp resolver, and use async resolve to look up an address. When that look-up fails, I throw an exception inside the asynchronous callback. I catch this exception outside the run() call, inside the main function. I then call stop() on my io_service instance (which is a global). However, when main() returns, the program hangs. It turns out to be waiting for an exit_event_ that never comes

boost.asio composed operation run in strand

五迷三道 提交于 2020-01-01 18:56:47
问题 The code: In thread 1: boost::async_read(socket, buffer, strand.wrap(read_handler)); In thread 2: strand.post([](){socket.async_write_some(buffer, strand.wrap(write_handler))}); It is clear that read_handler , async_write_some , write_handler protected by strand, they will not concurrent. However, async_read is an composed operation, it will call zero or more times to async_read_some, those async_read_some also need protect by strand or else they might concurrent with async_write_some in

What could happen if two threads access the same bool variable at the same time?

谁说胖子不能爱 提交于 2020-01-01 11:39:17
问题 I have a cross platform c++ program where I'm using the boost libraries to create an asynchronous timer. I have a global variable: bool receivedInput = false; One thread waits for and processes input string argStr; while (1) { getline(cin, argStr); processArguments(argStr); receivedInput = true; } The other thread runs a timer where a callback gets called every 10 seconds. In that callback, I check to see if I've received a message if (receivedInput) { //set up timer to fire again in 10