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
31
votes
2 answers

What is the advantage of strand in boost asio?

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 >…
StereoMatching
  • 4,971
  • 6
  • 38
  • 70
30
votes
1 answer

Boost asio io_service vs io_context

I am using boost asio library with c++. I found that io_service and io_context have similarities. for example both have method run and others. Could someone please detail differences between these two classes( like usage, conceptual idea, structural…
Vladimir Yanakiev
  • 1,240
  • 1
  • 16
  • 25
30
votes
5 answers

C++ Boost ASIO simple periodic timer?

I want a very simple periodic timer to call my code every 50ms. I could make a thread that sleeps for 50ms all the time (but that's a pain)... I could start looking into Linux API's for making timers (but it's not portable)... I'd like to use…
Scott
  • 1,176
  • 2
  • 13
  • 19
30
votes
6 answers

C++ Socket Server - Unable to saturate CPU

I've developed a mini HTTP server in C++, using boost::asio, and now I'm load testing it with multiple clients and I've been unable to get close to saturating the CPU. I'm testing on a Amazon EC2 instance, and getting about 50% usage of one cpu,…
waterlooalex
  • 13,642
  • 16
  • 78
  • 99
29
votes
5 answers

Boost::asio - how to interrupt a blocked tcp server thread?

I'm working on a multithreaded application in which one thread acts as a tcp server which receives commands from a client. The thread uses a Boost socket and acceptor to wait for a client to connect, receives a command from the client, passes the…
bythescruff
  • 1,869
  • 2
  • 17
  • 33
29
votes
5 answers

How to integrate Boost.Asio main loop in GUI framework like Qt4 or GTK

Is there any way to integrate Boost.Asio with Qt4 (preferred) or GTK main loop? GTK provides poll(2) like API so technically is should be possible. Qt provides its own networking layer, however I prefer to use existing code written for Boost.Asio. I…
Artyom
  • 31,019
  • 21
  • 127
  • 215
28
votes
5 answers

Boost::asio winsock and winsock 2 compatibility issue

My project uses windows.h in which winsock.h is used, and I need to include boost:assio which uses winsock2. So I get many errors that says Winsock.h already included. I can define WIN32_LEAN_AND_MEAN. so that windows.h wouldn't use winsock. The…
Dainius Kreivys
  • 525
  • 2
  • 8
  • 19
28
votes
10 answers

Boost linker error: Unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_system_category(void)"

I'm just getting started with Boost for the first time, details: I'm using Visual Studio 2008 SP1 I'm doing an x64 Build I'm using boost::asio only (and any dependencies it has) My code now compiles, and I pointed my project at the boost libraries…
waterlooalex
  • 13,642
  • 16
  • 78
  • 99
26
votes
4 answers

Using SSL sockets and non-SSL sockets simultaneously in Boost.Asio?

I'm in the process of converting a library to Boost.Asio (which has worked very well so far), but I've hit something of a stumbling block with regards to a design decision. Boost.Asio provides support for SSL, but a…
DSB
  • 417
  • 1
  • 4
  • 8
25
votes
9 answers

boost::asio::socket thread safety

( This is a simplified version of my original question ) I have several threads that write to a boost asio socket. This seems to work very well, with no problems. The documentation says a shared socket is not thread safe( here, way down at the…
ravenspoint
  • 19,093
  • 6
  • 57
  • 103
25
votes
4 answers

Some clarification needed about synchronous versus asynchronous asio operations

As far as I know, the main difference between synchronous and asynchronous operations (i.e. write() or read() vs async_write() and async_read()) The former ones don't return until the operation finish -or error, and the later ones, returns…
Old newbie
  • 811
  • 2
  • 11
  • 21
25
votes
2 answers

Poor boost.ASIO performance

I have a very simple server/client performance test using boost::asio on Windows and it seems to be performing really poorly. I'm hoping that I'm just using the library incorrectly and would appreciate any advice. I have a session class that writes…
Kranar
  • 1,136
  • 2
  • 13
  • 24
25
votes
5 answers

Using ZeroMQ together with Boost::ASIO

I've got a C++ application that is using ZeroMQ for some messaging. But it also has to provide a SGCI connection for an AJAX / Comet based web service. For this I need a normal TCP socket. I could do that by normal Posix sockets, but to stay cross…
Chris
  • 3,265
  • 5
  • 37
  • 50
24
votes
7 answers

Serialize and send a data structure using Boost?

I have a data structure that looks like this: typedef struct { unsigned short m_short1; unsigned short m_short2; unsigned char m_character; } MyDataType; I want to use boost::serialization to serialize this data structure, then use…
Runcible
  • 7,006
  • 12
  • 42
  • 62
24
votes
2 answers

C++ Boost ASIO: how to read/write with a timeout?

From reading other Stack Overflow entries and the boost::asio documentation, I've confirmed that there is no synchronous ASIO read/write calls that also provide an easy-to-use timeout as a parameter to the call. I'm in the middle of converting an…
Stéphane
  • 19,459
  • 24
  • 95
  • 136