boost-asio

How do I cleanly reconnect a boost::socket following a disconnect?

梦想的初衷 提交于 2019-11-27 05:36:01
问题 My client application uses a boost::asio::ip::tcp::socket to connect to a remote server. If the app loses connection to this server (e.g. due to the server crashing or being shutdown) I would like it to attempt a re-connect at regular intervals until it succeeds. What do I need to do on the client-side to cleanly handle a disconnect, tidy up and then repeatedly attempt reconnects? Currently the interesting bits of my code look something like this. I connect like this: bool MyClient::myconnect

How do I perform a nonblocking read using asio?

寵の児 提交于 2019-11-27 05:30:12
问题 I am attempting to use boost::asio to read and write from a device on a serial port. Both boost::asio:read() and boost::asio::serial_port::read_some() block when there is nothing to read. Instead I would like to detect this condition and write a command to the port to kick-start the device. How can I either detect that no data is available? If necessary I can do everything asynchronously, I would just rather avoid the extra complexity if I can. 回答1: You have a couple of options, actually. You

HTTPS request with Boost.Asio and OpenSSL

放肆的年华 提交于 2019-11-27 05:29:54
问题 I'm trying to read the ticker symbol at https://mtgox.com/api/0/data/ticker.php from my C++ application. I use Boost.Asio and OpenSSL because the service requires HTTPS. Boost version: 1.47.0 OpenSSL: 1.0.0d [8 Feb 2011] Win32 For the application; I took the example from http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/example/ssl/client.cpp to get started and modified it as follows: This is where I want to connect to: boost::asio::ip::tcp::resolver::query query("mtgox.com", "443"); I

Boost ASIO streambuf

一笑奈何 提交于 2019-11-27 05:22:11
I am confused about the input sequence and output sequence in boost asio::streambuf classes. According to the code examples (for sending data) in the documentation it seems that the buffer representing the input sequence is used for writting to socket and the one representing the output sequence is used for reading. Example - boost::asio::streambuf b; std::ostream os(&b); os << "Hello, World!\n"; // try sending some data in input sequence size_t n = sock.send(b.data()); b.consume(n); // sent data is removed from input sequence Now, is there a nomenclature problem? The nomenclature for boost:

How to integrate Boost.Asio main loop in GUI framework like Qt4 or GTK

寵の児 提交于 2019-11-27 05:13:08
问题 Is there any way to integrate Boost.Asio with Qt4 (preferred) or GTK main loop? GTK provides poll(2) like API so technically is should be possible. Qt provides its own networking layer, however I prefer to use existing code written for Boost.Asio. I want to integrate them without using an additional thread. Is there any reference how to do this for Qt4 (preferred) or GTKmm? Thanks. Edit I want to clearify several things to make the answer easier. Both Qt and GTKmm provide "select like"

What is the proper way to securely disconnect an asio SSL socket?

给你一囗甜甜゛ 提交于 2019-11-27 04:54:47
A boost-asio SSL/TLS TCP socket is implemented as an ssl::stream over a tcp::socket : boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket; In the TLS protocol, a cryptographically secure shutdown involves parties exchanging close_notify messages. Simply closing the lowest layer may make the session vulnerable to a truncation attack . In boost asio ssl async_shutdown always finishes with an error? @Tanner Sansbury describes the SSL shutdown process in detail with a number of scenarios and proposes using an async_shutdown followed by an async_write to disconnect an SSL stream prior

How to design proper release of a boost::asio socket or wrapper thereof

橙三吉。 提交于 2019-11-27 04:43:01
问题 I am making a few attempts at making my own simple asynch TCP server using boost::asio after not having touched it for several years. The latest example listing I can find is: http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/tutorial/tutdaytime3/src.html The problem I have with this example listing is that (I feel) it cheats and it cheats big, by making the tcp_connection a shared_ptr, such that it doesn't worry about the lifetime management of each connection. (I think) They do this

boost::asio async_read guarantee all bytes are read

自作多情 提交于 2019-11-27 04:42:56
问题 I have a server that receives a compressed string (compressed with zlib) from a client, and I was using async_receive from the boost::asio library to receive this string, it turns out however that there is no guarantee that all bytes will be received, so I now have to change it to async_read . The problem I face is that the size of the bytes received is variable, so I am not sure how to use async_read without knowing the number of bytes to be received. With the async_receive I just have a

can you set SO_RCVTIMEO and SO_SNDTIMEO socket options in boost asio?

允我心安 提交于 2019-11-27 03:35:13
问题 can you set SO_RCVTIMEO and SO_SNDTIMEO socket options in boost asio? If so how? Note I know you can use timers instead, but I'd like to know about these socket options in particular. 回答1: Absolutely! Boost ASIO allows you to access the native/underlying data, which in this case is the SOCKET itself. So, let's say you have: boost::asio::ip::tcp::socket my_socket; And let's say you've already called open or bind or some member function that actually makes my_socket usable. Then, to get the

C++ Socket Server - Unable to saturate CPU

…衆ロ難τιáo~ 提交于 2019-11-27 03:27:58
I've developed a mini HTTP server in C++, using boost::asio, and now I'm load testing it with multiple clients and I've been unable to get close to saturating the CPU. I'm testing on a Amazon EC2 instance, and getting about 50% usage of one cpu, 20% of another, and the remaining two are idle (according to htop). Details: The server fires up one thread per core Requests are received, parsed, processed, and responses are written out The requests are for data, which is read out of memory (read-only for this test) I'm 'loading' the server using two machines, each running a java application,