boost-asio

asio::read with timeout

家住魔仙堡 提交于 2019-11-27 20:34:43
问题 I need to know how to read (sync or async doesn't matters) with a timeout. I want to check if a device is connected with a serial port or not. For that I use asio::write and then I wait for the response of the device. If a device is connected asio::read(serial, boost::asio::buffer(&r,1)) works fine but if there is no device the program stops, which is is why I need the timeout I know that I need a deadline_timer but I have no idea how to use it in the async_read function. An example of how it

boost::asio threadpool vs. io_service_per_cpu design

你说的曾经没有我的故事 提交于 2019-11-27 20:18:49
Currently I´m not sure, I try to make a high-performance server, I got a 6Core CPU, so if I would use the "io_service_per_cpu" design, I have 6 io_service´s. I already heard that the threadpool design isn´t the best one, but I´m not sure about that. What knowledge do you have? Someone already made a Stress test with each, or something else? Sam Miller In my experience it is vastly easier to approach asynchronous application design with the following order: single thread and a single io_service multiple threads, each invoking io_service::run() from a single io_service . Use strands for handlers

Using boost::asio thread pool for general purpose tasks

大城市里の小女人 提交于 2019-11-27 20:17:33
In this blog I found a pretty neat example on how to create a simple thread pool using boost::asio. I basically want to use it like this: #include <thread> #include <functional> #include <boost/asio.hpp> int main ( int argc, char* argv[] ) { asio::io_service io_service; asio::io_service::work work(io_service); std::vector<std::thread> threadPool; for(size_t t = 0; t < std::thread::hardware_concurrency(); t++){ threadPool.push_back(thread(std::bind(&asio::io_service::run, &io_service))); } io_service.post(std::bind(an_expensive_calculation, 42)); io_service.post(std::bind(a_long_running_task,

Exception running boost asio ssl example

与世无争的帅哥 提交于 2019-11-27 19:09:54
问题 I'm trying to run the SSL examples from boost::asio and I'm getting an "Invalid argument" exception when I run them. I'm on Linux x86_64. http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/ssl/client.cpp http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/ssl/server.cpp Compiled with: g++ server.cpp -o server -lboost_system -lssl g++ client.cpp -o client -lboost_system -lssl Run like: $ ./server Usage: server <port> $ ./server 10000 Exception: Invalid argument $ .

Get Local IP-Address using Boost.Asio

亡梦爱人 提交于 2019-11-27 19:01:41
I'm currently searching for a portable way of getting the local IP-addresses. Because I'm using Boost anyway I thought it would be a good idea to use Boost.Asio for this task. There are several examples on the net which should do the trick. Examples: Official Boost.Asio Documentation Some Asian Page I tried both codes with just slight modifications. The Code on Boost.Doc was changed to not resolve "www.boost.org" but "localhost" or my hostname instead. For getting the hostname I used boost::asio::ip::host_name() or typed it directly as a string. Additionally I wrote my own code which was a

Which boost libraries are heading for TR2?

孤者浪人 提交于 2019-11-27 17:28:44
问题 If found this quote at boost.org: More Boost libraries are in the pipeline for TR2 It links to the TR2 call from proposals. But I can't seem to find any other information on which boost libraries are headed for TR2. I've seen a draft proposal for Boost.Asio, and I vaguely remember seeing something about Boost.System and Boost.Filesystem being proposed as well. Which boost libraries are headed for TR2? What else has been proposed for the TR2? Are there any good sources of information for this?

Exception running boost asio ssl example

被刻印的时光 ゝ 提交于 2019-11-27 17:28:09
I'm trying to run the SSL examples from boost::asio and I'm getting an "Invalid argument" exception when I run them. I'm on Linux x86_64. http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/ssl/client.cpp http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/ssl/server.cpp Compiled with: g++ server.cpp -o server -lboost_system -lssl g++ client.cpp -o client -lboost_system -lssl Run like: $ ./server Usage: server <port> $ ./server 10000 Exception: Invalid argument $ ./server 1000 Exception: Permission denied $ sudo ./server 1000 Exception: Invalid argument Not sure what

How to gracefully shutdown a boost asio ssl client?

我与影子孤独终老i 提交于 2019-11-27 16:04:15
问题 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

boost::asio io_service thread pool

笑着哭i 提交于 2019-11-27 14:44:38
问题 What's the proper usage of settings up a thread pool for io_service? These 2 statements from the documentation are throwing me off: io_service::run A normal exit from the run() function implies that the io_service object is stopped (the stopped() function returns true). Subsequent calls to run(), run_one(), poll() or poll_one() will return immediately unless there is a prior call to reset(). io_service::reset This function must be called prior to any second or later set of invocations of the

Boost.Asio as header-only

萝らか妹 提交于 2019-11-27 14:41:00
I want to use ASIO library from Boost in my project. Its doc say it can be header-only if regex is not used and SSL not used. However, running bcp for asio pulls a very many libraies some of which are with sources so need compiling, bjam etc. Can I somehow use ASIO in project as only headers, without libs/source? I only need ASIO, not other part of Boost. EDIT: ASIO want Boost.System which has a lib to link - can this dependency not be so that I can use header only ASIO? AFAIK you can get the non-boost version of asio from http://think-async.com/Asio/AsioAndBoostAsio "— Boost.Asio uses the