Questions tagged [boost-asio]

Boost.Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.

Most programs interact with the outside world in some way, whether it be via a file, a network, a serial cable, or the console. Sometimes, as is the case with networking, individual I/O operations can take a long time to complete. This poses particular challenges to application development. The Boost.Asio library is intended for programmers using C++ for systems programming, where access to operating system functionality such as networking is often required.

More information on Boost.Asio can be found here:

Notable alternatives for Boost.Asio:

4582 questions
12
votes
1 answer

What's the difference between boost::io_service poll_one and run_one?

io_service::poll_one Run the io_service object's event processing loop to execute one ready handler. vs io_service::run_one Run the io_service object's event processing loop to execute at most one handler. From that explanation it would seem…
Eloff
  • 20,828
  • 17
  • 83
  • 112
12
votes
2 answers

Low-latency read of UDP port

I am reading a single data item from a UDP port. It's essential that this read be the lowest latency possible. At present I'm reading via the boost::asio library's async_receive_from method. Does anyone know the kind of latency I will experience…
endian
  • 4,234
  • 8
  • 34
  • 42
12
votes
1 answer

Implementing a good C++0x error_condition?

I try to figure out how the new system_error together with error_code, error_category and not the least the (meant to implement portable error reporting) error_condition should be used. I think by reading boost.system I understand how I should use…
towi
  • 21,587
  • 28
  • 106
  • 187
12
votes
1 answer

Windows 10 ignores setsockopt IP_TOS

The short version: I am trying to set the IP_TOS field on the traffic my application is sending and even though setsockopt returns successfully and getsockopt returns the correct IP_TOS value, the traffic is untagged when leaving the Windows 10…
phill
  • 466
  • 7
  • 17
12
votes
3 answers

Boost.Asio socket destructor closes connection?

What exactly does the destructor of boost::asio::ip::tcp::socket do? I can't tell, even after scouring Boost docs and source code, if I need to use socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both); socket->close(); before calling…
owacoder
  • 4,815
  • 20
  • 47
12
votes
3 answers

boost asio deadline_timer

I expected the code below to print Hello, world! every 5 seconds, but what happens is that the program pauses for 5 seconds and then prints the message over and over with no subsequent pauses. What am I missing? #include #include…
shaz
  • 2,317
  • 4
  • 27
  • 37
12
votes
2 answers

Boost ASIO streambuf

I am confused about the input sequence and output sequence in boost asio::streambuf classes. According to the code examples (for sending data) in the documentation it seems that the buffer representing the input sequence is used for writting to…
Rohit
  • 371
  • 4
  • 18
12
votes
4 answers

Why does boost::asio::io_service not compile with std::bind?

I'm trying to compile simple test program with std::thread, std::bind and boost::asio using g++ 4.9.1 (-std=c++11). However, when creating new thread, it doesn't compile, when I use std::bind. On the other hand, when I switch to boost::bind…
eclipse
  • 693
  • 9
  • 30
12
votes
2 answers

boost::asio async_receive_from UDP endpoint shared between threads?

Boost asio specifically allows multiple threads to call the run() method on an io_service. This seems like a great way to create a multithreaded UDP server. However, I've hit a snag that I'm struggling to get an answer to. Looking at a typical…
oldtimer
  • 121
  • 1
  • 5
12
votes
1 answer

Remove all handlers from a boost::asio::io_service without calling them

I want to remove all handlers from an IO_service right before I reuse it. Is this possible? I'm writing unit tests that involve an asio::io_service. In between each test case I want to clear the handlers from the global io_service. I thought that…
deft_code
  • 57,255
  • 29
  • 141
  • 224
12
votes
3 answers

How to stop std thread safely?

I'm developing a chat server and I have a question. How to stop std::thread safely? it is very easy problem, like this. thread t(&func); t.join(); but, if func is has infinite loop, join is not working. this is my source. void…
BombPenguin
  • 211
  • 2
  • 3
  • 10
12
votes
1 answer

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

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…
user123003
12
votes
2 answers

using multiple io_service objects

I have my application in which listen and process messages from both internet sockets and unix domain sockets. Now I need to add SSL to the internet sockets, I was using a single io_service object for all the sockets in the application. It seems now…
Ravikumar Tulugu
  • 1,702
  • 2
  • 18
  • 40
12
votes
1 answer

How do you post a boost packaged_task to an io_service in C++03?

This is a follow-on from a previous question (here), but I'm working on a multithreaded application and I would like to post a Boost packaged_task to a threaded io_service. I'm stuck using a C++03 compiler (so std::move is out), and the…
John Doe
  • 301
  • 3
  • 11
12
votes
4 answers

Setting limit on post queue size with Boost Asio?

I'm using boost::asio::io_service as a basic thread pool. Some threads get added to io_service, the main thread starts posting handlers, the worker threads start running the handlers, and everything finishes. So far, so good; I get a nice speedup…
Jon Stewart
  • 393
  • 1
  • 4
  • 11