boost-asio

Boost ASIO async_read is not reading data from the client

故事扮演 提交于 2019-12-22 01:03:02
问题 I have a server/client application which works for a write from client to a read at server. Inside the startHandlig function in the server code, if I comment async_connect_1 and the return after it, then it works fine which involves sync write function. I added async_connect_1 function inside Service() class to asynchronously read from the socket. This function is called when a client connects to the server and this function returns immediately. I expect the callback function corresponding to

Detect aborted connection during Boost.Asio request [duplicate]

孤街醉人 提交于 2019-12-22 00:33:22
问题 This question already has answers here : Closed 7 years ago . 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

Extend asynchronous file io in boost::asio to Mac OS X

ε祈祈猫儿з 提交于 2019-12-21 20:46:42
问题 The boost::asio package contains classes for doing asynchronous file io in Windows using IO completion ports. To my understanding, there is no support for asynchronous file io for other platforms included in the asio package. I am wondering what would need to be done in order to extend asio with asynchronous file io support for at least Mac OS X, but also to some extent Linux. I am mostly interested in what would need to be done on the asio side of things, but since I am not that experienced

Reading a Serial Port Asynchronously Boost

寵の児 提交于 2019-12-21 20:44:21
问题 I am trying to read several bytes asynchronously from a serial port. Currently the code I am using (source is How do I perform a nonblocking read using asio?), only allows me to read 1 byte and then it exits. How do I get it so that the code keeps reading until there is no more incoming data in the serial port? Thanks :) void foo() { boost::asio::io_service io_svc; boost::asio::serial_port ser_port(io_svc, "/dev/ttyS0"); boost::asio::deadline_timer timeout(io_svc); unsigned char my_buffer[2];

How to cancel boost asio io_service post

自作多情 提交于 2019-12-21 20:27:41
问题 How can I cancel already posted callback: getIoService()->post(boost::bind(&MyClass::myCallback, this)); and keep other posted callbacks untouched? The problem is that I have some object that receives events from different thread and I post them to ioservice in order to handle events in main thread. What if at some point I want to delete my object - ioservice will try to execute already posted callbacks in destroyed object. And in this case I can't store any flag in object since it will be

Boost ASIO: How can a server know if a client is still connected?

℡╲_俬逩灬. 提交于 2019-12-21 16:47:14
问题 I am using boost::asio for a server/client application. The server only accepts one connection at a time. I am wondering what is the best way for the server to verify if the client is still connected. The purpose of this is that I would like to be able to know if the client has crashed, so that I can restart listening to new connection attempts. 回答1: In my application I am using following flags and my read comes out when client disconnects. Please try it if it in your application. Apply this

Verify at compile time that objects are created as shared_ptr

筅森魡賤 提交于 2019-12-21 13:42:20
问题 There are classes that I write (often as part of boost::asio ) whose objects depend on being wrapped in a shared_ptr because they use shared_from_this() . Is there a way to prevent an object from being compiled if it's not instantiated in a shared_ptr ? So, what I'm looking for: std::shared_ptr<MyClass> a = std::make_shared<MyClass>(); // should compile fine std::unique_ptr<MyClass> a = std::make_unique<MyClass>(); // compile error MyClass a; // compile error 回答1: Make its constructor private

dedicated thread for io_service::run()

两盒软妹~` 提交于 2019-12-21 09:12:03
问题 I want to provide a global io_service that is driven by one global thread. Simple enough, I just have the thread body call io_service::run() . However, that doesn't work as run ( run_one , poll , poll_one ) return if there is no work to do. But, if the thread repeatedly calls run(), it will busy loop when there is nothing to do. I'm looking for a way to get the thread to block while there isn't any work to be done in the io_service. I could add a global event to the mix for the thread to

C++ multiple multicast receiver with boost asio

拥有回忆 提交于 2019-12-21 06:29:24
问题 I have to implement a multicast receiver able to join a list of multicast groups and process received data in a specific thread using boost. I did try the following code..... boost::asio::io_service m_io_service; boost::asio::ip::udp::socket m_multicast_socket(m_io_service); // listen address boost::asio::ip::address listen_address = boost::asio::ip::address::from_string("0.0.0.0"); // listen port unsigned short multicast_port = m_configuration->m_multicast_interface_port; boost::asio::ip:

C++ multiple multicast receiver with boost asio

梦想与她 提交于 2019-12-21 06:29:02
问题 I have to implement a multicast receiver able to join a list of multicast groups and process received data in a specific thread using boost. I did try the following code..... boost::asio::io_service m_io_service; boost::asio::ip::udp::socket m_multicast_socket(m_io_service); // listen address boost::asio::ip::address listen_address = boost::asio::ip::address::from_string("0.0.0.0"); // listen port unsigned short multicast_port = m_configuration->m_multicast_interface_port; boost::asio::ip: