boost-asio

boost::asio::yield_context: unexpected forced_unwind exception

北战南征 提交于 2019-12-20 20:01:40
问题 I'm tring to write my custom async function for boost::asio as described here. However I'm getting boost::coroutines::detail::forced_unwind exception on line with result.get #include <boost/chrono.hpp> #include <boost/asio.hpp> #include <boost/asio/spawn.hpp> #include <boost/asio/steady_timer.hpp> #include <iostream> namespace asio = ::boost::asio; template <typename Timer, typename Token> auto my_timer (Timer& timer, Token&& token) { typename asio::handler_type<Token, void (::boost::system:

Does boost::asio::io_service preserve the order of handlers?

余生长醉 提交于 2019-12-20 18:30:48
问题 Does boost::asio::io_service guarantee that handlers are called in the same order that they are given via post()? I can't find anything saying this in the documentation. Assume that calls to io_service::post are serialized. 回答1: The current implementation does execute things in the sequence you post them, but ordering is only guaranteed for handlers that are explicitly post()ed through a strand . 回答2: afaik if you want guaranteed ordering of post handler execution you have to use strand as

Use same udp socket for async receive/send

[亡魂溺海] 提交于 2019-12-20 14:39:58
问题 I use the same socket in my udp server in order to receive data from clients on some port, and later after processing of requests respond to to clients using ip::ud::socket ::async_send_to Receive is done async with async_receive_from also. The socket uses same ioService (it's the same socket after all) The documentation does not state clearly if one can have at a moment the same udp socket receive datagrams from client A (in async way) and possibly send another datagram to client B (async

Low-latency read of UDP port

偶尔善良 提交于 2019-12-20 10:49:08
问题 I am reading a single data item from a UDP port. It's essential that this read be the lowest latency possible. At present I'm reading via the boost::asio library's async_receive_from method. Does anyone know the kind of latency I will experience between the packet arriving at the network card, and the callback method being invoked in my user code? Boost is a very good library, but quite generic, is there a lower latency alternative? All opinions on writing low-latency UDP network programs are

boost:asio thread pool implementation for occasionally synchronized tasks

ⅰ亾dé卋堺 提交于 2019-12-20 10:38:15
问题 I have a "main" function that performs many small, independent tasks each once per time step. However, after each time step, I must wait for all of the tasks to complete before stepping forward. I want to make the program multithreaded. I have tried implementations with the boost-offshoot threadpool, and I've tried using a vector of (shared pointers to) threads, and I've tried the asio threadpool ideas (using an io_service, establishing some work, then distributing run to the threads and

Boost error codes reference

♀尐吖头ヾ 提交于 2019-12-20 09:45:27
问题 Does anyone know where to find a reference for boost error codes. In particular, error codes returned by asynchronous socket handlers?, Google and grepping the header files have tuned up empty. 回答1: It looks (from my relatively limited googling) like those are actually system codes. More info here: http://en.highscore.de/cpp/boost/errorhandling.html 回答2: I extracted the error values from asio/error.hpp on Linux (I'm using header only asio not boost::asio by the way), here they are: asio:

Boost Asio single threaded performance

泄露秘密 提交于 2019-12-20 09:24:01
问题 I am implementing custom server that needs to maintain very large number (100K or more) of long lived connections. Server simply passes messages between sockets and it doesn't do any serious data processing. Messages are small, but many of them are received/send every second. Reducing latency is one of the goals. I realize that using multiple cores won't improve performance and therefore I decided to run the server in a single thread by calling run_one or poll methods of io_service object.

boost::asio cleanly disconnecting

天大地大妈咪最大 提交于 2019-12-20 08:59:17
问题 Sometimes boost::asio seems to disconnect before I want it to, i.e. before the server properly handles the disconnect. I'm not sure how this is possible because the client seems to think its fully sent the message, yet when the server emits the error its not even read the message header... During testing this only happens maybe 1 in 5 times, the server receives the client shut down message, and disconnects the client cleanly. The error: "An existing connection was forcibly closed by the

Trying to understand Boost.Asio custom service implementation

喜你入骨 提交于 2019-12-20 08:30:58
问题 I'm thinking about writing a custom Asio service on top of an existing proprietary 3rd party networking protocol that we are currently using. According to Highscore Asio guide you need to implement three classes to create a custom Asio service: A class derived from boost::asio::basic_io_object representing the new I/O object. A class derived from boost::asio::io_service::service representing a service that is registered with the I/O service and can be accessed from the I/O object. A class not

C++ Boost: initializing endpoint after contructor

风格不统一 提交于 2019-12-20 07:38:28
问题 I try to make a class to use UDP. I want to have the endpoint initialized after the constructor, so I modify it as follows: class UdpSender { private: boost::asio::ip::udp::endpoint endpoint; boost::asio::ip::udp::socket socket; string multicast_address; unsigned short multicast_port; boost::thread_group threads; // thread group boost::thread* thread_main; // main thread boost::thread* thread_listen; // listen thread boost::thread* thread_getsend; // get/send thread boost::mutex stopMutex;