boost-asio

Is there a bug in the boost asio HTTP Server 3 example or boost bug?

爷,独闯天下 提交于 2019-11-29 15:46:55
boost library version 1.53 Debian Linux 6.0 ( Linux 2.6.32-5-amd64 on x86_64 ) It is hard to test own software when valgrind log contains lots of warnings. So with no changes I built the HTTP server3 example and run it under the Valgrind. Take a look, please. Did I miss something? valgrind --tool=helgrind --log-file=valgrind.log ./server3 0.0.0.0 83 5 /root/server3 Here is the Helgrind log (edited to 30000 body characters limit, full log http://pastebin.com/Vkbr9vsA ): Helgrind, a thread error detector Copyright (C) 2007-2012, and GNU GPL'd, by OpenWorks LLP et al. Using Valgrind-3.9.0.SVN and

In Boost ASIO how can I set the source IP address to impersonate another server's IP address?

本秂侑毒 提交于 2019-11-29 13:04:57
I have a Boost ASIO-based C++ server program and I'd like to be able to set the source IP address used by TCP to that of another server. I know one can read the source and destination IP addresses but presumably they can be set as well? Presumably if I set the "wrong" source IP address in the C++ code there will be some interaction with the network stack. Won't the network stack re-set the source IP address on the way out even if the C++ code is right? Is the right way to do this to write C++ ASIO code to pick a specific virtual network interface? One that is configured with the "wrong" static

boost::io_service How to guarantee handler execution sequence

最后都变了- 提交于 2019-11-29 11:46:20
I have a thread pool with boost::io_service on top. I use it for different CPU-bound tasks in whole application. For some tasks, I have to guarantee that tasks will be executed in specified order (decoding video stream). Using io_service::strand guaranties that tasks will not be executed currently, but it has no guarantee about the order of execution. In other words, task #5 may be executed before task #4. Is there any method to solve that problem, other than scheduling next task after executing of current. strand provides both the guarantee of not executing completion handlers concurrently

Segfault with asio standalone when classes in separate files

坚强是说给别人听的谎言 提交于 2019-11-29 11:35:25
问题 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

What is the difference between asio::tcp::socket's async_read_some and async_receive?

淺唱寂寞╮ 提交于 2019-11-29 11:17:43
问题 What is the difference between: boost::asio::tcp::socket::async_read_some() boost::asio::tcp::socket::async_receive() As far as I can tell their documentation is identical. Which should I prefer? 回答1: Their specification in the networking TR2 proposal (5.7.10.2 basic_stream_socket members) is identical too: On async_receive: Effects: Calls this->service.async_receive(this->implementation, buffers, 0, handler). On async_read_some: Effects: Calls this->service.async_receive(this->implementation

How to avoid data race with `asio::ip::tcp::iostream`?

二次信任 提交于 2019-11-29 10:37:29
My question How do I avoid a data race when using two threads to send and receive over an asio::ip::tcp::iostream ? Design I am writing a program that uses an asio::ip::tcp::iostream for input and output. The program accepts commands from the (remote) user over port 5555 and sends messages over that same TCP connection to the user. Because these events (commands received from the user or messages sent to the user) occur asynchronously, I have separate transmit and receive threads. In this toy version, the commands are "one", "two" and "quit". Of course "quit" quits the program. The other

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

谁说我不能喝 提交于 2019-11-29 08:19:52
问题 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(/*

Reading JSON from a socket using boost::asio

人盡茶涼 提交于 2019-11-29 07:59:27
I am currently trying to transfer some JSON data over the network from a client to a server using the socket API of boost-asio. My client essentially does this: int from = 1, to = 2; boost::asio::streambuf buf; ostream str(&buf); str << "{" << "\"purpose\" : \"request\"" << "," << endl << "\"from\" : " << from << "," << endl << "\"to\" : " << to << "," << endl << "}" << endl; // Start an asynchronous operation to send the message. boost::asio::async_write(socket_, buf, boost::bind(&client::handle_write, this, _1)); On the server side I have the choice between various boost::asio::async_read*

boost::asio read from /dev/input/event0

我们两清 提交于 2019-11-29 07:48:05
I am looking to use boost::asio to read from a 12 digit keypad. I currently can do it without boost, this way: fd = open ("/dev/input/event0", 0_NONBLOCK); read (fd, &ev, sizeof ev); Do you know how I could do this with boost::asio? I am using Linux and c++. This post and this post are useful. I would not use serial port port (io, "/dev/usb/hiddev0") because its not serial, right? Thank you. On my system, event2 represents the mouse, and the following simple readloop program works like a charm. Run as root : #include <boost/asio.hpp> #include <boost/asio/posix/stream_descriptor.hpp> #include

How do I handle fork() correctly with boost::asio in a multithreaded program?

微笑、不失礼 提交于 2019-11-29 07:13:33
问题 I'm having some trouble grasping how to correctly handle creating a child process from a multithreaded program that uses Boost Asio in a multithreaded fashion. If I understand correctly, the way to launch a child process in the Unix world is to call fork() followed by an exec*() . Also, if I understand correctly, calling fork() will duplicate all file descriptors and so on and these need to be closed in the child process unless marked as FD_CLOEXEC (and thereby being atomically closed when