boost-asio

Do boost asio sockets have proper RAII cleanup

我与影子孤独终老i 提交于 2019-11-29 07:02:52
I tried looking through source but I cant navigate that much of a template code. Basically: this is what documentation says (for close() ): Remarks For portable behaviour with respect to graceful closure of a connected socket, call shutdown() before closing the socket. I can do that manually, but if possible it would be nice to rely on RAII. So if I have socket going out of scope do I need to call shutdown() and close() on it, or it will be done automatically? One can rely on the socket performing proper cleanup with RAII. When an IO object, such as socket, is destroyed, its destructor will

What is the advantage of strand in boost asio?

荒凉一梦 提交于 2019-11-29 06:11:40
问题 Studying boost asio and find out a class called "strand", as far as I understand. If there are only one io_service associated to a specific strand and post the handle by the strand. example(from here) boost::shared_ptr< boost::asio::io_service > io_service( new boost::asio::io_service ); boost::shared_ptr< boost::asio::io_service::work > work( new boost::asio::io_service::work( *io_service ) ); boost::asio::io_service::strand strand( *io_service ); boost::thread_group worker_threads; for( int

SSL certificates and Boost asio

半腔热情 提交于 2019-11-29 04:39:25
问题 Hello I'm trying to download content from webpage that uses https via C++. My very basic client program taken from the Boost asio examples compiles and runs fine, but when I test it eg with Google: www.google.co.uk/?gws_rd=ssl, it gives me the error "handshake: certificate verify failed". I think this is because ctx.set_default_verify_paths() doesn't contain a path with a certificate for Google (I'm on Windows). I'm very new to SSL, please can you help me with the following questions: 1) When

Reading from serial port with Boost Asio

回眸只為那壹抹淺笑 提交于 2019-11-29 04:36:05
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::asio::streambuf response; boost::system::error_code error; std::string s1, s2; if (boost::asio::read

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

余生长醉 提交于 2019-11-29 04:33:27
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 this at the moment: void handle_read(boost::system::error_code ec, std::size_t nr) { std::cout << "handle

how to add proxy support to boost::asio?

不羁岁月 提交于 2019-11-29 04:17:51
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 application? I found the answer myself. It's quite simple: http://www.jmarshall.com/easy/http/

How to gracefully shutdown a boost asio ssl client?

旧时模样 提交于 2019-11-29 03:35:45
The client does some ssl::stream<tcp_socket>::async_read_some() / ssl::stream<tcp_socket>::async_write() calls and at some point needs to exit, i.e. it needs to shutdown the connection. Calling ssl::stream<tcp_socket>::lowest_layer().close() works, but (as it is expected) the server (a openssl s_server -state ... command) reports an error on closing the connection. Looking at the API the right way seems to be to call ssl::stream<tcp_socket>::async_shutdown() . Now there are basically 2 situation where a shutdown is needed: 1) Client is in the async_read_some() callback and reacts on a 'quit'

How do I create a Boost.Asio Server that can handle multiple clients at once?

烈酒焚心 提交于 2019-11-29 02:46:57
I can create a simple TCP server that can respond to one client, but I don't know how to create a server that can handle multiple clients at once. I have referred to examples like TCP daytime async server, but it just sends the data to client. What I need to create is keep alive the connection as long as client exists. Both Client and Server will communicate in Json. Consider one case where client will give {"hello":"Client"} and server should respond {"Hello":"Server"} , and say another {"message":"How are you?"} and its response {"response" : "Fine"} . I need to handle multiple clients at

asio::async_write and strand

早过忘川 提交于 2019-11-29 02:38:50
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 ?) Tanner Sansbury 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 conditions are true: The initiating async_write(...) call is running within m_strand() :

Boost.Asio: Is it a good thing to use a `io_service` per connection/socket?

三世轮回 提交于 2019-11-29 00:29:33
I want to create an application that implements one-thread-per-connection model. But each connection must be stoppable. I have tried this boost.asio example which implements the blocking version of what I want. But after a little bit questioning I've found out that there is no reliable way to stop the session of that example. So I've tried to implement my own. I had to use asynchronous functions. Since I want to make a thread to manage only one connection and there is no way to control which asynchronous job is employed to which thread, I decided to use io_service for each connection/socket