boost-asio

Can a boost::asio::yield_context be used as a deadline_timer handler when doing cancel?

时光毁灭记忆、已成空白 提交于 2019-12-01 12:51:49
问题 I'd like to be able to do an asynchronous wait on a specific event. There are a lot of similar questions and answers on here (and all compile and work for me) but none with my specific scenario. Basically, what I need to be able to do is an async_wait, passing a yield context as the handler, to a timer that waits indefinitely, and is then canceled by another thread. For example, there is this question which does something very similar, but instead of using a yield context, it uses a separate,

boost::asio::streambuf::consume - Injects garbage character

假装没事ソ 提交于 2019-12-01 12:42:17
When I lose connection, in my server code, I try to reconnect in a loop forever. Once I reconnect, I send a login message to the component I am connected to. That component then sends back a login response that looks like "MyResponse" The initial connection works fine. After I reconnect, however, I get garbage before the expected message, that looks like: "ýMyResponse" After googling this. I see many questions on Stack Overflow about the boost::asio::streambuf that is used for async sockets in boost::asio. Particularly about reusing he buffer. I have followed the advice there and called

Crash : terminate called after throwing an instance of 'std::system_error' what(): Resource deadlock avoided

跟風遠走 提交于 2019-12-01 12:30:41
I have a simple client /server application the code of which is mentioned below. Please run the server in one shell and the client in another shell in linux. First start the server and then the client. When the server is done with it's work, it crashes with following exception: terminate called after throwing an instance of 'std::system_error' what(): Resource deadlock avoided This happens from the line m_thread->join() from inside the function Service::HandleClient I have no clue on what's going on.. Can someone please check the code.. I just want that the server application should also get

How to run boost asio resolver service on more threads?

偶尔善良 提交于 2019-12-01 11:23:51
I am using boost::asio::ip::udp::resolver in an SNMPV2 implementation to determine wheather a host is reachable or not. using Resolver = boost::asio::ip::udp::resolver; Resolver resolver(ioService); Resolver::query query(connectOptions.getHost(), connectOptions.getPort()); Resolver::iterator endpointIterator; BOOST_LOG_SEV(logger, Severity::debug) << "Waiting for async resolve"; endpointIterator = resolver.async_resolve(query, yield); BOOST_LOG_SEV(logger, Severity::debug) << "Async resolve done"; if (endpointIterator == Resolver::iterator{}) { // unreachable host using namespace boost::system

boost::asio - peeking into a socket buffer

孤人 提交于 2019-12-01 11:09:39
I use boost::asio::read (or may be the equivalent async_read ) to read some data from a socket. Is it possible that I leave the bytes read in the underlying socket so that next time I call read on the socket I receive again that data ? Like Simon said, you can't do it with boost::asio::read() (or boost::asio::async_read() ). However, for read() you could call native_handle() on the socket to get the socket descriptor and then use ::recvmsg() with the MSG_PEEK flag. Similarly, you could call async_read() with null_buffers() as the receive buffer and then use the native_handle() / ::recvmsg()

asio implicit strand and data synchronization

半城伤御伤魂 提交于 2019-12-01 11:05:57
When I read asio source code, I am curious about how asio making data synchronized between threads even a implicit strand was made. These are code in asio: io_service::run mutex::scoped_lock lock(mutex_); std::size_t n = 0; for (; do_run_one(lock, this_thread, ec); lock.lock()) if (n != (std::numeric_limits<std::size_t>::max)()) ++n; return n; io_service::do_run_one while (!stopped_) { if (!op_queue_.empty()) { // Prepare to execute first handler from queue. operation* o = op_queue_.front(); op_queue_.pop(); bool more_handlers = (!op_queue_.empty()); if (o == &task_operation_) { task

Boost::asio server/client socket, access permissions and ports issue

大憨熊 提交于 2019-12-01 11:02:21
A new error arose with my server (boost::asio based) once I implemented reconnection on my client but I am not even sure if this is the cause. The scenario is like this: I run Client.exe which can reconnect in case a server is not running. Client.exe creates several objects which connect independently to my server. So several connections to my servers are created from the same process. Because I haven't run the server yet, every object try to reconnect every 3 seconds (some of them concurrently so not always at the same time). The problem occurs sometimes when I start the server: I get the "An

boost::asio::streambuf::consume - Injects garbage character

北慕城南 提交于 2019-12-01 09:51:51
问题 When I lose connection, in my server code, I try to reconnect in a loop forever. Once I reconnect, I send a login message to the component I am connected to. That component then sends back a login response that looks like "MyResponse" The initial connection works fine. After I reconnect, however, I get garbage before the expected message, that looks like: "ýMyResponse" After googling this. I see many questions on Stack Overflow about the boost::asio::streambuf that is used for async sockets

Running a function on the main thread from a boost thread and passing parameters to that function

余生颓废 提交于 2019-12-01 09:45:58
问题 I have some code running in a boost thread that modifies stuff handled by the main thread which is not working and it makes sense. On android i would have the Handler which is a message queue that would execute my code on the main thread and i can pass whatever parameters i want to this handler. I want to do the same with boost so on my main thread i do the following: boost::thread workerThread(boost::bind(&SomeClass::pollService, this)); My pollService method: SomeClass::pollService() { /

Which Boost error codes/conditions are returned by which Boost.Asio calls?

℡╲_俬逩灬. 提交于 2019-12-01 09:45:21
问题 I am currently writing a TCP I/O facility that uses Boost.Asio as the underlying socket API, and I've noticed that Boost.Asio seems to lack documentation on which specific Boost error codes/conditions can result from each individual operation (e.g. function/method call or asynchronous operation). All that I've been able to find is the error code API and some informal error code lists, none of which correlate specific codes to specific operations . This apparent lack of documentation is