boost-asio

Has anyone done a performance analysis of boost::asio?

ⅰ亾dé卋堺 提交于 2019-12-18 12:18:56
问题 I require socket-like local IPC. I used named pipes and overlapped IO on windows and I want to rewrite the application to boost::ASIO so that it can use UNIX domain sockets as well. I've recently reviewed parts of the libevent library and I know it only supports socket() and select() for windows in the 1.4 version. As overlapped IO is very efficient leaving it out is obviously an unacceptable trait which is being adressed in version 2 (which is in alpha). Another example of sub-optimal

boost::asio::buffer: Getting the buffer size and preventing buffer overflow?

拈花ヽ惹草 提交于 2019-12-18 11:57:50
问题 I have the two following functions for sending and receiving packets. void send(std::string protocol) { char *request=new char[protocol.size()+1]; request[protocol.size()] = 0; memcpy(request,protocol.c_str(),protocol.size()); request_length = std::strlen(request); boost::asio::write(s, boost::asio::buffer(request, request_length)); } void receive() { char reply[max_length]; size_t reply_length = boost::asio::read(s, boost::asio::buffer(reply, request_length)); std::cout << "Reply is: "; std:

Is there any way to asynchronously wait for a future in Boost Asio?

旧街凉风 提交于 2019-12-18 11:48:16
问题 My problem is the following. I start several operations asynchronously, and I want to continue until all of them are finished. Using Boost Asio, the most straightforward way to do this is the following. Suppose tasks is some kind of container of objects that support some asynchronous operation. tasksToGo = tasks.size(); for (auto task: tasks) { task.async_do_something([](const boost::system::error_code& ec) { if (ec) { // handle error } else { if (--taslsToGo == 0) { tasksFinished(); } } });

HOWTO: post messages between threads with Boost::asio?

空扰寡人 提交于 2019-12-18 09:46:42
问题 Sorry for my english I've searched around, but did not get an answer to this question: I have a windows application project, using boost thread libraries. I want to post messages(or, invoke callbacks) from a worker's thread to the main UI thread. I studied the samples in boost::asio, all of them used in a blocked main thread, but my UI thread is working asynchronous. Would you please help me? thanks a lot! 回答1: Since the UI thread has its own message loop, you can't call in its context the

Is there a bug in the boost asio HTTP Server 3 example or boost bug?

风流意气都作罢 提交于 2019-12-18 09:11:15
问题 boost library version 1.53 Debian Linux 6.0 ( Linux 2.6.32-5-amd64 on x86_64 ) It is hard to test own software when valgrind log contains lots of warnings. So with no changes I built the HTTP server3 example and run it under the Valgrind. Take a look, please. Did I miss something? valgrind --tool=helgrind --log-file=valgrind.log ./server3 0.0.0.0 83 5 /root/server3 Here is the Helgrind log (edited to 30000 body characters limit, full log http://pastebin.com/Vkbr9vsA): Helgrind, a thread error

Cannot use movable objects with Boost.Asio

走远了吗. 提交于 2019-12-18 08:22:28
问题 Reading this, I got the impression that this code should work: class Connection : public std::enable_shared_from_this<Connection> { public: Connection(tcp::socket&& socket) : socket_(std::move(socket)) {} private: tcp::socket socket_; }; But the compiler issues this error in the constructor: Call to implicitly-deleted copy constructor of 'tcp::socket' (aka'basic_stream_socket<boost::asio::ip::tcp>') I have also defined BOOST_ASIO_HAS_MOVE . I use Xcode 4.6.3 and in the compiler settings I

Read until a string delimiter in boost::asio::streambuf

自闭症网瘾萝莉.ら 提交于 2019-12-18 04:19:15
问题 I would like to use the very convenient Boost async_read_until to read a message until I get the \r\n\r\n delimiter. I like using this delimiter because it's easy to debug with telnet and make multiline commands. I just signal end of command by two new lines. I call async_read_until like this: void do_read() { boost::asio::async_read_until(m_socket, m_input_buffer, "\r\n\r\n", std::bind(&player::handle_read, this, std::placeholders::_1, std::placeholders::_2)); } And my handler looks like

Reading from serial port with Boost Asio

冷暖自知 提交于 2019-12-18 04:16:40
问题 I'm want to check for incoming data packages on the serial port, using boost.asio . Each data packet will start with a header that is one byte long, and will specify what type of the message has been sent. Each different type of message has its own length. The function I want to write should listen for new incoming messages continually, and when it finds one it should read it, and call some other function to parse it. My current code is as follows: void check_for_incoming_messages() { boost:

how to add proxy support to boost::asio?

偶尔善良 提交于 2019-12-18 04:10:30
问题 In my desktop application I added access to various internet resources using boost::asio. All i do is sending http requests (i.e to map tile servers) and read the results. My code is based on the asio sync_client sample. Now i get reports from customers who are unable to use these functions as they are running a proxy in their company. In a web browser they can enter the address of their proxy and everything is fine. Our application is unable to download data. How can i add such support to my

asio::async_write and strand

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 03:49:32
问题 asio::async_write(m_socket, asio::buffer(buf, bytes), custom_alloc(m_strand.wrap(custom_alloc(_OnSend)))); Does this code guarantee that all asynchronous operation handlers(calls to async_write_some) inside async_write are called through strand? (or it's just for my_handler ?) 回答1: With the following code: asio::async_write(stream, ..., custom_alloc(m_strand.wrap(...))); For this composed operation, all calls to stream.async_write_some() will be invoked within m_strand if all of the following