boost-asio

Read boost::asio UDP Broadcast Response

橙三吉。 提交于 2019-12-11 09:09:43
问题 I am attempting to use boost::asio to implement a simple device discovery protocol. Basically I want to send a broadcast message (port 9000) with 2 byte payload. Then read the response from the device (assuming currently it exists). In wireshark I can see the broadcast is been sent and that the device is responding. However, in my example code I get that the bytes returned is 0 in the UDP read, not 30 bytes of data. No. Time Source Destination Protocol Length 1 0.00000 192.168.0.20 255.255

How to use signal_set to terminate boost asio io_service run

这一生的挚爱 提交于 2019-12-11 09:03:23
问题 I am trying to add a ^C handler to a boost io_service. Prior to adding, the service would exit when it ran out of I/O (all the associated sockets had closed). After adding the signal_set, it doesn't exit until it gets a SIGINT. For example: #include <boost/asio.hpp> int main() { boost::asio::io_service io_service; boost::asio::signal_set exit_signal_set{io_service, SIGINT}; exit_signal_set.async_wait ([&](boost::system::error_code const&, int) { std::cerr << "exiting, sigint" << std::endl; io

Dealing with code redefining int types(uint16_t, int16_t, etc) and Boost not liking it

我们两清 提交于 2019-12-11 08:38:48
问题 So i am in a bit of stand off here and im not sure exactly how to go about proceeding, or if its even fixable... We use a 3rd party SDK provided by another team, this SDK must be used for our app to function properly. In this SDK, there are lines like this #define uint16_t UINT16 #define uint8_t UINT8 The issue is in Boost, more specifically the ASIO/Details/cstdint.hpp file has lines that are using std::uint16_t using std::uint8_t My app wont compile now because its really doing using std:

ASIO - How to stop simple coroutine based server?

别等时光非礼了梦想. 提交于 2019-12-11 08:07:57
问题 I have the following simple coroutine-based server: class Server { private: boost::asio::io_service Service; boost::asio::ip::tcp::acceptor Acceptor; boost::asio::ip::tcp::socket Socket; private: void Accept(boost::asio::yield_context Yield); void Write(boost::asio::yield_context Yield); public: Server(): Acceptor(Service), Socket(Service) {} void Open(unsigned short PortNum); void Run(); void Stop(); }; void Server::Accept(boost::asio::yield_context Yield) { boost::system::error_code ec; for

Unexpected end of file while reading mpstat output with BOOST ASIO async_read_until

前提是你 提交于 2019-12-11 07:58:42
问题 I try to read the output of mpstat command (collecting cpu information every second, ie: "mptstat -P ALL 1") in order to get information about cpu and core usage. On a multicore cpu, I get an unexpected "end of file" status just after having read the first measurements. It appears that mpstat formats its output in such a way that measurements for all cores are separated by an empty line. I have used async_read_until with a delimiter equal to '\n'. Please find below a small reproducer. With

Can't turn TCP_NODELAY OFF

落爺英雄遲暮 提交于 2019-12-11 07:57:53
问题 I'm using Boost asio to send a TCP message. I set the NO_DELAY option because this is a 'real time' control system. I see the PSH flag set in the message using Wireshark. I am happy with the performance and it is working as expected. For interest, I decided to turn the NO_DELAY off and measure the performance difference. I swapped my existing code: m_tcpSocket.open(boost::asio::ip::tcp::v4()); boost::asio::ip::tcp::no_delay noDelayOption(true); m_tcpSocket.set_option(noDelayOption); // snip

What's the lifetime of boost::asio::ip::tcp::resolver::iterator from async_resolve?

家住魔仙堡 提交于 2019-12-11 07:34:20
问题 When I call boost::asio::ip::tcp::resolver::async_resolve , my handler receives an ip::tcp::resolver::iterator that iterates through one or more ip::tcp::resolver::entries . What is their lifetime, and what is the handle that keeps them alive? For example, if I get the first entry and launch a tcp::async_connect to it, then in the async_connect handler, can I iterate to the next entry and launch another async_connect to the next entry (as long as I pass the iterator to the async_connect

Boost-ASIO async_receive_from function overload issue (+ dynamic pointer)

烂漫一生 提交于 2019-12-11 07:15:59
问题 I am trying to create a simple asynchronous receiver using the Boost library. I followed the examples as well as books, and this is what I was able to cook up so far: class networkUDPClient { public: utilityTripleBuffer * buffer; char testBuffer[20] = { 0 }; const char * hostAddress; unsigned int port; boost::asio::io_service service; boost::asio::ip::udp::socket socket; boost::asio::ip::udp::endpoint listenerEndpoint; boost::asio::ip::udp::endpoint senderEndpoint; // Function Definitions

Reserving memory for asynchronous send buffers (boost asio sockets)

风流意气都作罢 提交于 2019-12-11 06:57:49
问题 I'm trying to change the implementation of a fire-and-forget UDP send-function from being synchronous to asynchronous. The current simplified synchronous function looks like this: ssize_t UDPTransport::send_to(const char * buffer, size_t bufferSize) { return mPSocket->send_to(boost::asio::buffer(buffer, bufferSize), mOutputEndpoint); } I've got a thread_group set up and io_service::run() is set to use it. However, the problem is that I have no guarantee that buffer will exist after this call

EOF in boost::async_read with thread_pull and boost 1.54

你离开我真会死。 提交于 2019-12-11 06:48:16
问题 I have a strange problem with my server application. My system is simple: I have 1+ devices and one server app that communicate over a network. Protocol has binary packets with variable length, but fixed header (that contain info about current packet size). Example of packet: char pct[maxSize] = {} pct[0] = 0x5a //preambule pct[1] = 0xa5 //preambule pct[2] = 0x07 //packet size pct[3] = 0x0A //command ... [payload] The protocol is built on the principle of a command-answer. I use boost::asio