boost-asio

When performing an async_write with a tcp socket, when is the handler called?

十年热恋 提交于 2019-12-04 04:53:10
问题 This is just a simple question of how async_write behaves with tcp sockets. Basically, when working with a tcp socket, does the write handler get called when the data gets written to the socket, or when an ack is received from the destination? 回答1: AFAIK, the handler gets called as soon as data are written into the socket's kernel buffer. 回答2: Same behavior as the BSD socket's send() - it completes when the OS has a copy of the data. This will be before an ACK. 回答3: The only guarantee

How to use Boost.Asio c++?

拥有回忆 提交于 2019-12-04 04:43:05
问题 I would try to use the library to use socket Boost.Asio c++ on multiple platforms. I downloaded the latest version here: http://sourceforge.net/projects/boost/files/boost/1.46.1/ but now what do I use in my code? I have compile it? include just enough? Can you tell me the steps? 回答1: How you use it depends on what you want to do, ;-). The documentation is found here: http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio.html You will find lots of examples that should suite your needs. For

Does boost::asio support websockets?

╄→гoц情女王★ 提交于 2019-12-04 04:35:16
问题 I posted a question earlier asking why does my server (written in C++ and boost::asio ) can't connect with a client (written in Javascript). Is the problem that the Javascript Websockets are different than boost::asio sockets ? Does boost::asio not support websockets ? What is the easiest way to work this out ? 回答1: Boost.Asio doesn't directly support WebSocket but there's this great open source library out there which is very closely modeled to Boost.Asio and works the way that you expect.

boost::asio, thread pools and thread monitoring

人走茶凉 提交于 2019-12-04 04:19:36
I've implemented a thread pool using boost::asio , and some number boost::thread objects calling boost::asio::io_service::run() . However, a requirement that I've been given is to have a way to monitor all threads for "health". My intent is to make a simple sentinel object that can be passed through the thread pool -- if it makes it through, then we can assume that the thread is still processing work. However, given my implementation, I'm not sure how (if) I can monitor all the threads in the pool reliably. I've simply delegated the thread function to boost::asio::io_service::run() , so

What is boost::asio::ssl::context::load_verify_file and how to work with it?

﹥>﹥吖頭↗ 提交于 2019-12-04 04:03:14
Theare is a wary small amount of boost::asio:: ssl small C++ educational codes base online. Even less on boost::asio::ssl::context::load_verify_file So I found one from here code with minimal modifications - compiles and runs with boost 1.47.0: #include <boost/asio.hpp> #include <boost/asio/ssl.hpp> #include <boost/bind.hpp> #include <iostream> #include <istream> #include <ostream> #include <string> class client { public: client(boost::asio::io_service& io_service, boost::asio::ssl::context& context, boost::asio::ip::tcp::resolver::iterator endpoint_iterator) : socket_(io_service, context) {

boost asio and endian

好久不见. 提交于 2019-12-04 03:59:47
I cant tell, does boost asio handle endian? Asio does convert things like port into network order. The conversion functions are not exposed as part of the official interface and are hidden in the detail namespace instead (e.g. boost::asio::detail::socket_ops::host_to_network_short ). boost::asio::socket_'s do not perform any byte order conversion. 来源: https://stackoverflow.com/questions/524453/boost-asio-and-endian

Creating a HTTPS request using Boost Asio and OpenSSL

瘦欲@ 提交于 2019-12-04 03:51:25
问题 I have created a simple HTTP request wherein I am sending GET,POST and PUT requests to the server. Next I want to switch to HTTPS connection using boost asio library, how should I proceed? I have an Executor Class that resolves and connects to the server and a RequestCreator Class that creates the request. 回答1: I happen to just have posted such a thing in a comment (...): You just connect over ssl. @Milind coliru.stacked-crooked.com/a/9546326fd1def416 So perhaps it is helpful to you. Live On

Boost.Asio thread safety

回眸只為那壹抹淺笑 提交于 2019-12-04 01:42:58
问题 Is it safe to call async_write & async_read from different threads in situation when io_service::run() was called from only one thread? Thank you! 回答1: Is it safe to call async_write & async_read from different threads Yes, but with a caveat. You can safely do this for distinct socket objects Thread Safety Distinct objects: Safe . Shared objects: Unsafe . 回答2: The documentation is conservative on that and says "no". But I'm doing this anyway in one of my linux programs and it seems to work

Boost ASIO: SSL handshake() never finishes

浪子不回头ぞ 提交于 2019-12-04 01:31:35
I have a C++ client app that uses Boost ASIO to make SSL connections to various servers. But against 2 specific servers, the SSL connection cannot be established. It hangs in the call to boost::asio::ssl::stream::handshake() . I've used Wireshark to observe the conversation between client and server. A working SSL connection seems to do this: sslsocket.lowest_layer().connect( endpoint, ec ); C -> SYN -> S C <- SYN ACK <- S C -> ACK -> S sslsocket.handshake( SSLSocket::client, ec ); C -> 209 bytes -> S C <- 690 bytes <- S C -> 198 bytes -> S C <- 415 bytes <- S ...and at this point the ASIO

Boost error codes human-readable description

时光毁灭记忆、已成空白 提交于 2019-12-03 23:11:17
I'm catching errors in Boost Asio program like if (!error) { //do stuff } else { std::cout << "Error : " << error << std::endl; //handle error } But the error isn't human-readable (e.g. connecting to SSL server without certificate gives error asio.ssl:335544539). Is there any better way how to display error ? If you are likely using boost::system::error_code you can call: error.message() to get a more human-friendly message. Using operator<< translates into: os << ec.category().name() << ':' << ec.value() Here you can check a detailed overview of the available members in error_code . 来源: https