boost-asio

Continuous boost::asio reads

纵然是瞬间 提交于 2019-12-24 00:46:54
问题 I'm experimenting with Boost::asio, and I'm trying to make a client that reads and outputs to console packets sent from a server. The server uses a proprietary protolcol. It sends a timer update every second, responds to ping, and can reply with a list of files when the client asks for it. I have a decent grasp of asynchronous networking, but I'm having a problem. Here's the code: class JReader { public: JReader(boost::asio::io_service &io_s) : socket_(io_s) { tcp::resolver resolver(io_s);

What can cause an exception 16: “mutex: Resource busy” to be thrown (using Boost / BB10)?

自作多情 提交于 2019-12-23 23:46:18
问题 I've ported a long-working stable library written in C++ and Boost to Blackberry 10. The library transfers files between devices. The library compiles and links well, and runs just fine. However, I consistently encounter a thrown exception on my Blackberry 10 device after 1, 2, or 3 files have been transferred. Catching the exception as a boost::system::system_error in the source code shows it is exception 16, with a text of "mutex: Resource busy". Here is the source code where the exception

ipv4 and ipv6 from any valid address

点点圈 提交于 2019-12-23 20:00:41
问题 I'm trying to get both the ipv4 and ipv6 address from any string address, be it by ipv4, ipv6, or DNS address. I can create my own function to do so, but I'm trying to take expert advice and utilize built-in capabilities. Is there a way to input an address string of any format, and have both ipv4 and ipv6 boost addresses returned? 回答1: Getting an address from the DNS name involves... querying a naming server (DNS!). If you want to enumerate the results, use a resolver in asio: http://www

Memory management in asynchronous C++ code

我们两清 提交于 2019-12-23 19:56:43
问题 I have been working with boost::asio for a while now and while I do understand the concept of the asynchronous calls I am still somewhat befuddled by the memory management implications. In normal synchrous code the object lifetime is clear. But consider a scenario similar to the case of the daytime server: There might be multiple active connections which have been accept ed. Each connection now sends and receives some data from a socket, does some work internally and then decides to close the

boost asio - connect using an ip address

自作多情 提交于 2019-12-23 17:46:48
问题 I want to connect to a server socket specified by a destination ip address and port number. boost::asio::connect seems it does not allow to use this. I have ip destination as a unsigned int value. Update: I am able to do ba::ip::tcp::endpoint endpoint( ba::ip::address(ba::ip::address_v4(req.IpDst())), ntohs(req.Port())); But how can I use endpoint with connect ? 回答1: It is possible to use: socket.connect(endpoint); 来源: https://stackoverflow.com/questions/9040424/boost-asio-connect-using-an-ip

C++ Boost ASIO async_send_to memory leak

旧时模样 提交于 2019-12-23 17:18:45
问题 I am currently working on a UDP socket client. I am currently noticing a memory leak and I've tried several things in hopes to squash it, but it still prevails. In my main, I have a char* that has been malloc 'd. I then call the below function to send the data: void Send(const char* data, const int size) { Socket.async_send_to(boost::asio::buffer(data, size), Endpoint, boost::bind(&MulticastSender::HandleSendTo, this, boost::asio::placeholders::error)); } If I run this code, it will always

Simple interface for getting HTML content in Boost.Asio

人走茶凉 提交于 2019-12-23 12:49:47
问题 There are a lot of examples how to make HTTP request to a server and get reply via boost.asio library. However, I couldn't find a good example of simple interface and wondering, if I need to implement it myself. For instance, if I need to get content of http://www.foo.bar/path/to/default.html , is there any way to get a content without validating URL, making HTTP request and parsing server answer? Basically, I am looking for something like this: std::string str = boost::asio::get_content(

What is the difference between poll and run?

荒凉一梦 提交于 2019-12-23 12:43:12
问题 Does anyone have an example illustrating the difference between boost::asio::io_service::poll and boost::asio::io_service::run ? More specifically what is the difference between calling join_all() on a thread_group executing run() and on another one executing poll() ? Do both guarantee that all events have finished? In the documentation available at http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/io_service/run/overload1.html, it is said: The poll() function may also be

Using boost::asio::io_service::post()

冷暖自知 提交于 2019-12-23 12:14:31
问题 First i asked this Running a function on the main thread from a boost thread and passing parameters to that function so now i am trying this: The following is a console c++ project where i perfectly simulated my big project TestServicePost.cpp #include "stdafx.h" #include "SomeClass.h" int _tmain(int argc, _TCHAR* argv[]) { SomeClass* s = new SomeClass(); while(true) { s->update(); } return 0; } SomeClass.h #include <boost/thread.hpp> #include <boost/asio.hpp> #include <queue> class

Who is failing, boost, clang, or gcc? Issue with std::chrono used with boost::asio

删除回忆录丶 提交于 2019-12-23 08:53:57
问题 As noted by this question, boost::asio now can use the C++11 chrono objects if they are available. However, the following code compiles with but not with clang 3.6.0-svn223366-1~exp1 #include <iostream> #include <boost/chrono.hpp> #include <boost/bind.hpp> #include <boost/asio.hpp> #include <boost/asio/steady_timer.hpp> #include <chrono> #include <thread> #include <functional> boost::asio::io_service ioservice; boost::asio::steady_timer timer(ioservice); void function() { std::cout <<