boost-asio

boost::asio::deadline_timer with std::chrono time values

回眸只為那壹抹淺笑 提交于 2019-12-04 23:08:19
I have an application that uses asio deadline timers. The rest of the application uses std::chrono constructs for its time values, and it feels awkward to use boost::posix_time for only the stuff that touches asio. I'd like to use std::chrono throughout the application if I can, for consistency, readability, etc. It seems to me that the answer would involve using the timer's template: typedef boost::asio::basic_deadline_timer<std::chrono::system_clock::time_point> my_deadline_timer_type; my_deadline_timer_type a_timer(io_service); Except this blows up badly at compile time...many lines of

How does Boost Asio's hostname resolution work on Linux? Is it possible to use NSS?

久未见 提交于 2019-12-04 20:47:32
问题 I'm attempting to make my networked application work locally (with both the server and client running on the same computer) when there is no network connection. This seems to "just work" occasionally, but most of the time I end up with: terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >' what(): Host not found (authoritative) Aborted The code I'm currently using is: tcp::resolver:

Can't use asio::placeholders::error in non-Boost version of Asio

牧云@^-^@ 提交于 2019-12-04 20:17:24
问题 I'm trying to use the non Boost version of Asio in a project. I'm writing a callback to stream_protocol::acceptor::async_accept . The signature requires asio::placeholders::error to be passed but when I do so, I get the following error: error: no member named 'error' in namespace 'asio::placeholders' Following the source, I can see error is there but of type undefined , which is new to me. Am I missing something? Am I supposed to do some sort of pre-processing of the libraries? 回答1: In short,

Simple proxy using C++/boost::asio/libcurl - can't download images

萝らか妹 提交于 2019-12-04 19:51:14
I'm trying to implement a very simple proxy server with the following code. You set your browser's proxy to 192.168.1.x:8080 and web pages are accessible through the proxy. #include <ctime> #include <iostream> #include <string> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> #include <boost/asio.hpp> #include <boost/algorithm/string.hpp> #include <curl/curl.h> #include <cstdlib> using boost::asio::ip::tcp; int port=8080; //CURL *curl; //CURLcode res; static size_t write_to_string(void *ptr, size_t size, size_t count, void *stream) { ((std:

Detect aborted connection during Boost.Asio request [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-12-04 19:33:56
Possible Duplicate: How to check if socket is closed in Boost.Asio? Is there an established way to determine whether the other end of a TCP connection is closed in the asio framework without sending any data? Using Boost.asio for a server process, if the client times out or otherwise disconnects before the server has responded to a request, the server doesn't find this out until it has finished the request and generated a response to send, when the send immediately generates a connection-aborted error. For some long-running requests, this can lead to clients canceling and retrying over and

Why would we need many acceptors in the Boost.ASIO?

我们两清 提交于 2019-12-04 19:06:09
As known, we can use multiple acceptors in boost::asio. boost::asio::io_service io_service_acceptors; std::vector<boost::thread> thr_grp_acceptors; unsigned int thread_num_acceptors = 2; for(size_t i = 0; i < thread_num_acceptors; ++i) { thr_grp_acceptors.emplace_back( boost::bind(&boost::asio::io_service::run, &io_service_acceptors)); But is there any sense in doing io_service_acceptors more than 1? Boost.ASIO uses optimal non-blocking demultiplexing mechanism (epoll, IOCP, ...). Also even if network error will occur after epoll and before accept then accept will not been blocked , because we

boost.asio composed operation run in strand

穿精又带淫゛_ 提交于 2019-12-04 17:46:06
The code: In thread 1: boost::async_read(socket, buffer, strand.wrap(read_handler)); In thread 2: strand.post([](){socket.async_write_some(buffer, strand.wrap(write_handler))}); It is clear that read_handler , async_write_some , write_handler protected by strand, they will not concurrent. However, async_read is an composed operation, it will call zero or more times to async_read_some, those async_read_some also need protect by strand or else they might concurrent with async_write_some in thread 2. But from the code, strand only wrap read_handler , how asio make all intermediate operations

enumerating ipv4 and ipv6 address of my cards using boost asio

南楼画角 提交于 2019-12-04 17:36:43
问题 I am trying to enumerate ipv4 and ipv6 addresses of all the network cards(I have 2 cards) my pc. I am using the following code to do that. using boost::asio::ip::tcp; boost::asio::io_service io_service; tcp::resolver resolver(io_service); tcp::resolver::query query(boost::asio::ip::host_name(),""); tcp::resolver::iterator it=resolver.resolve(query); while(it!=tcp::resolver::iterator()) { boost::asio::ip::address addr=(it++)->endpoint().address(); if(addr.is_v6()) { std::cout<<"ipv6 address: "

boost asio async_connect success after close

旧街凉风 提交于 2019-12-04 16:03:45
问题 Single-threaded application. It happens not every time, only after 1.5 hours of high load. tcp::socket::async_connect tcp::socket::close (by deadline_timer) async_connect_handler gives success error_code (one of a million times), but socket is closed by(2). 99.999% of time it gives errno=125 (ECANCELED). Is it possible that socket implementation or boost asio somehow do this: async_connect async success posted to io_service close by timer async success handled by me, not affected by close

Configuring TCP keep_alive with boost::asio [duplicate]

别等时光非礼了梦想. 提交于 2019-12-04 15:52:32
问题 This question already has answers here : can you set SO_RCVTIMEO and SO_SNDTIMEO socket options in boost asio? (3 answers) Closed 5 years ago . Both Linux and Windows support TCP keep-alive packets. They can be activated and configured with (system-dependent) setsockopt calls, see e.g. this article for the Linux case. When using boost::asio there appears to be support for keep-alive messages, see the current documentation. However that page only covers activating it. In several new responses