boost-asio

boost::asio::ip::tcp::socket is connected?

百般思念 提交于 2019-11-30 10:39:57
问题 I want to verify the connection status before performing read/write operations. Is there a way to make an isConnect() method? I saw this, but it seems "ugly". I have tested is_open() function as well, but it doesn't have the expected behavior. 回答1: TCP is meant to be robust in the face of a harsh network; even though TCP provides what looks like a persistent end-to-end connection, it's all just a lie, each packet is really just a unique, unreliable datagram. The connections are really just

Linking errors when compiling boost asio on Linux

≯℡__Kan透↙ 提交于 2019-11-30 10:09:31
I have been running through a few tutorials of boost and the libraries it has. I ran through the basic tutorial for boost: http://www.boost.org/doc/libs/1_52_0/more/getting_started/unix-variants.html and it worked fine. I am having issues with the asio tutorial: http://www.boost.org/doc/libs/1_50_0/doc/html/boost_asio/tutorial/tutdaytime1/src.html It looks like linking errors, but I am including the same path as before: g++ -I /usr/local/boost_1_52_0 test.cpp -o example Error: /tmp/cce4EZME.o: In function `__static_initialization_and_destruction_0(int, int)': test.cpp:(.text+0x57b): undefined

AF_NETLINK (netlink) sockets using boost::asio

末鹿安然 提交于 2019-11-30 09:55:45
I'm writing multicast client/server application based on this and this ; which work great. However, I would also need to do something when the number of active network interfaces in the computer changes, something like what the program in the example section of this page does. I guess I should use the tools in boost::asio::local, but I am unsure whether I should use boost::asio::local::datagram_protocol or boost::asio::local::stream_protocol or... An example of how to do something as similar as possible would be really helpful. Thanks. As you noticed there's a little bit extra code that has to

Segfault with asio standalone when classes in separate files

丶灬走出姿态 提交于 2019-11-30 08:38:02
The below is as minimal of an example as I can get. It does need to be in separate files as that seems to be what causes the segmentation fault error. I'm using Mingw x32 4.8.1 with Asio standalone 1.10.6 . I've also tested with TDM GCC 4.7.1 and Mingw x64 4.8.1. All of these under Windows produce the same segfault. There's no such issue under Linux with the latest version of GCC. edit: I've just finished testing on Mingw-w64 5.2.0 (the Mingw-Builds build of it). Same problem. I've also tested compiling this with TDM GCC 4.8.1 on a fresh virtual machine and get the same segfault. Edit: I've

boost::asio::async_write, writing data larger than 65536 bytes

拈花ヽ惹草 提交于 2019-11-30 08:37:09
问题 I'm attempting to write jpeg frames via a socket to a client using async_write() . I used the boost asynchronous TCP daytime server example as a starting point. #include <ctime> #include <iostream> #include <string> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> #include <boost/asio.hpp> using boost::asio::ip::tcp; std::string make_daytime_string() { using namespace std; // For time_t, time and ctime; time_t now = time(0); return ctime(

Who uses Boost ASIO?

怎甘沉沦 提交于 2019-11-30 08:17:39
问题 I would like to know how popular is Boost ASIO. Is it being used in any popular network-intensive software ? 回答1: The systems software for managing an IBM Blue Gene/Q supercomputer uses Boost.Asio extensively. The source code is available under the Eclipse Public License (EPL) if you're interested. 回答2: http://think-async.com/Asio/WhoIsUsingAsio 回答3: Boost is extensively being used in serious networking software, take example of HPX uses boost libraries. HPX is implemented in C++11 and

How to asynchronously read input from command line using boost asio in Windows?

我们两清 提交于 2019-11-30 07:29:53
I found this question which asks how to read input asynchronously, but will only work with POSIX stream descriptors, which won't work on Windows. So, I found this tutorial which shows that instead of using a POSIX stream descriptor I can use a boost::asio::windows::stream_handle . Following both examples I came up with the code below. When I run it, I cannot type anything into the command prompt, as the program immediately terminates. I'd like it to capture any input from the user, possibly into a std::string , while allowing other logic within my program to execute (i.e. perform asynchronous

How to create a Boost.Asio socket from a native socket?

ぃ、小莉子 提交于 2019-11-30 07:02:24
I am merely trying to create a boost ip::tcp::socket from an existing native socket. In the assign function , the first parameter must be a "protocol_type" and the second must be a "native_type", but it never explains what these are or gives an example of its use. I'm guessing the second should be the socket descriptor, but I'd really appreciate clarification. void SendData (int socket, std::string message) { boost::asio::io_service ioserv; boost::asio::ip::tcp::socket s(ioserv); s.assign(/* what goes here? */, /* ..and here? */); s.send(boost::asio::buffer(message)); } "Native type" is just

Boost.Asio: Is it a good thing to use a `io_service` per connection/socket?

佐手、 提交于 2019-11-30 06:49:11
问题 I want to create an application that implements one-thread-per-connection model. But each connection must be stoppable. I have tried this boost.asio example which implements the blocking version of what I want. But after a little bit questioning I've found out that there is no reliable way to stop the session of that example. So I've tried to implement my own. I had to use asynchronous functions. Since I want to make a thread to manage only one connection and there is no way to control which

What is the advantage of strand in boost asio?

谁说我不能喝 提交于 2019-11-30 06:48:35
Studying boost asio and find out a class called "strand", as far as I understand. If there are only one io_service associated to a specific strand and post the handle by the strand. example(from here ) boost::shared_ptr< boost::asio::io_service > io_service( new boost::asio::io_service ); boost::shared_ptr< boost::asio::io_service::work > work( new boost::asio::io_service::work( *io_service ) ); boost::asio::io_service::strand strand( *io_service ); boost::thread_group worker_threads; for( int x = 0; x < 2; ++x ) { worker_threads.create_thread( boost::bind( &WorkerThread, io_service ) ); }