Menu
  • HOME
  • TAGS

Obtaining the sig_int value from siginfo in boost::siginfo handler

c++,linux,boost-asio

In short, no. In the presence of sigaction(), Boost.Asio registers its internal signal handler as sa_handler and does not set the SA_SIGINFO flag. Hence, Boost.Asio's signal handler never receives the siginfo_t associated with the signal, and cannot propagate it to the user's SignalHandler when completing the async_wait() operation. Here is...

C++ lambda, not seeing function and argument?

c++,multithreading,c++11,lambda,boost-asio

In the lambda that is calling callAFunctionHere, the this that is captured is the one for the instance of class A::TimerService, but you are trying to implicitly use members of an class A instance. You need a reference to an object of type A, and use that object's members. class...

How to prevent c++ asio tcp server from shutdown?

c++,boost,boost-asio

It looks like you should probably create some wait condition before accepting new connection if you're "out of ID"s. Because, if you don't, you can simply continue accepting by making acceptor_.async_accept(new_session->socket(), boost::bind(&chat_server::handle_accept, this, new_session, boost::asio::placeholders::error)); unconditional, but you have a loop: you'll be wasting resources accepting connections that you can't...

ASIO handler arguments and boost::bind, compile time error

boost,handler,boost-asio

The error code cannot be taken by reference. Make it by-value or by const&: void on_data_recv(boost::system::error_code/* ec */, size_t /*bytes_transferred*/) { Also, consider using the Asio specific placeholders: socket.async_read_some(boost::asio::buffer(recv_buffer), boost::bind(&RPC::on_data_recv, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); Also use proper lock guards. We're in C++! It's easy to make things exception-safe, so why not?...

Error while sending encrypted data with Boost::asio::async_send_to

c++,encryption,aes,boost-asio,crypto++

The key here is that the erroneous data begins after the first null (0x00) value in your encrypted data array. The following line: strcpy(newSendBuffer, encSendBuffer.c_str()); ...looks like it's only copying up to the data until that null byte into newSendBuffer. The send function is sending that buffer contents just fine;...

How to know which version of openssl boost ssl is using

c++,openssl,boost-asio

Boost will use the openssl version provided by your system (or explicitly specified during compilation/linkage, check your build script) It depends on your linkage type, if you link statically against OpenSSL, you will need to recompile. If you are linking dynamically, then updating the DLL/shared object will be enough...

asio :how does server actively send information to client while listening to client at the same time?

c++,c++11,tcp,boost-asio

I hope I got your question correctly and you also want to understand how asio works with async operations. In brief, everything happens in run function of io_service object. When you call async_write or async_read in some function, you register a callback (that will be called when some event happens)...

Getting started with network programming in Qt [closed]

c++,qt,network-programming,boost-asio

Trying to answer your first question, it depends on which platforms are you targeting (Windows, Linux, OSX...). You could use native OS socket api (bsd sockets or winsock) but Qt provides very good abstractions for these so for the sake of simplicity I would stick with it. I'm unfamiliar with...

assigning io_service to work - boost::asio

c++,boost-asio

Assuming you mean boost::asio::io_service::work work(io_service); because boost::asio::io_service is not copyable, you can do that in the constructor init list like normal: Foo::Foo(boost::asio::io_service &io_service) : work_member(io_service) { // stuff } ...

C2228: Error with TCP asio server

c++,boost,boost-asio

Where is socket defined? sounds like it isn't properly defined causing the write and read_until functions to throw the error. read_some and write_some are called inside the write and read_until (edit) looking at your code, unless socket is a global vairable, how is it getting passed into your session function,...

Move constructor is not called with boost::asio::ip::tcp::socket

c++,c++11,boost,boost-asio,move-constructor

This is a known bug with the compiler. The bug ticket mentions that this has been fixed in VS 2015 RTM. As a workaround, consider creating a shim to move the socket. Here is a small example demonstrating this approach: #include <memory> #include <thread> #include <boost/asio.hpp> void Func(boost::asio::ip::tcp::socket) {} int...

How to deal with extra characters read into ASIO streambuf?

c++,c++11,boost,boost-asio

While the read_until() operations commit all data read into the streambuf's input sequence, they return a bytes_transferred value containing the number of bytes up to and including the first delimiter. In essence, it provides the size of the frame, and one can limit istream to only read a portion of...

How to catch strange undefined behaviour in C++ code?

c++,debugging,boost,gdb,boost-asio

On ubuntu, I like to run with valgrind (http://valgrind.org/). sudo apt-get install valgrind valgrind ./mypgrogram It doesn't report all issues, but when it does, it will report the nature and origin. Also recommended: valgrind --db-attach=yes ./myprogram Which allows you to debug (backtrace, inspect) and continue the program when a violation/uninitialized...

How to save JSON response of HTTP GET in a .json file in C++?

c++,json,boost-asio

Well, actually this was a cake walk. I apologise to waste your time. To get just the JSON string output in the file I did the following. // Writing the remaining data to output. freopen("JSONoutput.json","w",stdout); std::cout << s.rdbuf() << "\n" << std::endl; freopen() : Reuses stream to either open the...

C++ URDL Compile Errors with Xcode 6.1 / LLVM 6.0

c++,xcode,boost,clang,boost-asio

Problem Solved ! :) Download the URDL Version from Github instead of the Website think-async.com as I did before.

boost::iostream readline stop after 4096 bytes

c++,boost,boost-asio

I'm not reproducing this with Ubuntu linux 14.10 64 bit gcc 4.8.2 boost_1_57 localhost traffic Did you check there are no linefeeds in the input? If I feed it a continues stream of input, I do not detect such issues. E.g. with netcat, Live On Coliru for a in {1..1024};...

boost::asio::io_service::run does not return while having no work

c++,c++11,boost,boost-asio

Apparently if you choose to define BOOST_ASIO_ENABLE_HANDLER_TRACKING then you must do so in all boost::asio translation units. I don't see this mentioned in the documentation, but I did find it on the Boost mailing list. When I add add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING) to your CMakeLists.txt so it is applied globally then I don't...

How to use boost::asio with Linux GPIOs

c++,boost-asio,gpio,epoll

As far as I know, it is not possible to get this particular behavior with Boost.Asio. While the kernel flags some files on the procfs and sysfs as pollable, they do not provide the stream-like behavior that is expected from boost::asio::posix::stream_descriptor and its operations. Boost.Asio's epoll reactor is edge-triggered (see...

What does boost::asio::spawn do?

c++,boost,boost-asio,boost-coroutine

In short: When spawn() is invoked, Boost.Asio performs some setup work and then will use a strand to dispatch() an internal handler that creates a coroutine using the user provided function as an entry point. Under certain conditions, the internal handler can be will be invoked within the call to...

What means blocking for boost::asio::write?

c++,boost,boost-asio

In short, boost::asio::write() blocks until all data has been written to the stream; it does not block until all data has been transmitted. To wait until data has been transmitted, consider using tcdrain(). Each serial port has both a receive and transmit buffer within kernel space. This allows the kernel...

How to connect signal to boost::asio::io_service when posting work on different thread?

c++,multithreading,boost,boost-asio,signals-slots

In light of new information, the problem is with your boost::bind. You are trying to call a member function without an object to call it on: you are trying to call ProcessData but you haven't told the bind on which object you wish to call it on. You need to...

SSL certificates and Boost asio

c++,boost,openssl,boost-asio

Most OpenSSL installations will install trusted certificates as part of the installation process, and boost::asio::ssl::context::set_default_verify_paths() is fairly good at finding the correct paths. The certification verification is failing because the the client is attempting to verify the peer's certificates with hostname verification (rfc2818), and is checking for the literal "host.name"...

send the full contents of a ring buffer on subscription and then send new data

c++,linux,boost-asio

You should just do what you intend to. You absolutely don't need a streambuf to use with Boost Asio: http://www.boost.org/doc/libs/release/doc/html/boost_asio/reference/buffer.html If the problem is how to avoid having the producer "wait" until all consumers (read: connections) are done transmitting the data, you can always use ye olde trick of alternating...

Boost Asio Error

c++,boost,windows-7,boost-asio

I'm going to assume from the symptoms that you run on Windows. On windows, static_mutex is implemented as a named (interprocess) mutex and gets "opened" using CreateMutexW: If the mutex is a named mutex and the object existed before this function call, the return value is a handle to the...

Avoid socket inheritance when starting Linux service from C++ application

c++,linux,sockets,boost,boost-asio

If you're referring to the socket descriptors themselves being inherited by exec'd child processes, and this being undesirable, then you could pass SOCK_CLOEXEC when creating the sockets with socket(2) to make sure that they are closed when you execute other programs. (This won't close the connection by the way, since...

Boost Asio, async UDP client - crash on shutdown

c++,boost,boost-asio

The destruction of AsyncUDPClient does not properly synchronize with the thread(s) running the io_service. This can result in undefined behavior being invoked when a thread processing the io_service attempts to interact with the AsyncUDPClient and its io_service after their lifetime has ended. To resolve this, do not detach from the...

win7 boost::asio::windows::stream_handle constructor throws error

windows-7,boost-asio

You might use GetStdHandle, so: HANDLE isfhandle = GetStdHandle(STD_INPUT_HANDLE); However, I don't think consoles support asynchronous IO in windows: The handle must be to an object that supports overlapped I/O. If a handle is provided, it has to have been opened for overlapped I/O completion. For example, you must specify...

Using Boost in a DLL project (ActiveX)

c++,boost,dll,visual-studio-2013,boost-asio

The short answer is to do something like this: C:\local\boost_1_58_0>bjam.exe runtime-link=static and remove BOOST_ALL_NO_LIB is its set, then build the DLL again. That should fix that....

boost::asio::serial_port and RTS pin

c++,boost,serial-port,boost-asio

I ended up using the windows api (OS specific) approach to solve my problem. #include <iostream> #include <cstdlib> #include <string> #include <windows.h> namespace comm{ class rs232 { const HANDLE commDevice; const DWORD clear_RTS = 4; const DWORD set_RTS = 3; public: rs232( HANDLE commDeviceIn ): commDevice(commDeviceIn) {} rs232( std::string commName...

boost::asio read n bytes from socket to streambuf

c++,boost,boost-asio,boost-serialization,streambuf

There are overloads for both boost::asio::read() and boost::asio::async_read() that accept instances of boost::asio::basic_streambuf as its buffer: read(SyncReadStream&, basic_streambuf&); read(SyncReadStream&, basic_streambuf&, CompletionCondition); read(SyncReadStream&, basic_streambuf&, boost::system::error_code&); read(SyncReadStream&, basic_streambuf&, CompletionCondition, boost::system::error_code&); async_read(AsyncReadStream&, basic_streambuf&, ReadHandler);...

How to run Boost.Asio server on port 80?

c++,boost,boost-asio

Run as root. The problem is that you don't have the permission to bind to a privileged port (<1024 on most systems). If you're certain that the child process of Xcode runs as root, find out which process is already listening on port 80 (lsof and netstat)...

Why does read() fail with EAGAIN when piping to a program using boost::asio for STDIN/STDOUT?

c++,linux,boost,boost-asio

The way that most shells and terminals work is that stdin and stdout are read/write file descriptors for the same file. Consider the following: $ echo FOO >&0 FOO Congratulations, you've just written something to stdin's file descriptor. The other half of the file can be found in the fcntl(2)...

Signature for function taking boost::bind as an argument (boost::asio timer callback)?

c++,boost,boost-asio

Indeed the return type of boost::bind is an expression template, and much more complicated than a function type. It is, after all, not a function but a function object (complete with bound attribute values) of an on-the-fly synthesized type. This type is implementation defined and you don't need to know...

Passing a unique_ptr reference to boost::bind?

c++,gcc,boost,boost-asio,boost-bind

You'd need C++-14 and generalized lambda capture to make this work -- you'd need to move the unique pointer into the lambda. Instead, just use a shared_ptr, which std::bind understands natively: std::shared_ptr<manager> m; m = std::make_shared<manager>(); io.post(std::bind(&manager::run, std::move(m))); The std::move is optional but ensures that m doesn't keep the manager...

Boost asio send and receive messages

boost,boost-asio

Since it's apparently safe to assume you just want to send /any/ message by the simplest means possible: Live On Coliru #include <boost/asio.hpp> struct Client { boost::asio::io_service& io_service; boost::asio::ip::tcp::socket socket; Client(boost::asio::io_service& svc, std::string const& host, std::string const& port) : io_service(svc), socket(io_service) { boost::asio::ip::tcp::resolver resolver(io_service); boost::asio::ip::tcp::resolver::iterator endpoint =...

Does BOOST asio supports eventfd? like epoll

c++,boost,boost-asio

The documentation describes some, but not all, of the things the io_service class can do. Note the that it says "including", not "only". Also, the next sentence in the documentation reads: The io_service class also includes facilities intended for developers of custom asynchronous services. If you are reading or writing...

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

c++11,boost,clang,boost-asio

The chrono documentation describes this Support for the std::chrono facilities is automatically enabled for g++ 4.6 and later, when the -std=c++0x or -std=gnu++0x compiler options are used. (Note that, for g++, the draft-standard monotonic_clock is used in place of steady_clock.) Support may be disabled by defining BOOST_ASIO_DISABLE_STD_CHRONO, or explicitly enabled...

Resuming asio coroutine from another thread

c++,multithreading,boost-asio

A coroutine runs within the context of a strand. In spawn(), if one is not explicitly provided, a new strand will be created for the coroutine. By explicitly providing strand to spawn(), one can post work into the strand that will be synchronized with the coroutine. Also, as noted by...

Boost::ASIO multithreaded writing stale data to socket?

multithreading,sockets,boost,tcp,boost-asio

Okay, Sam Miller gets the credit for the answer here, but he posted it as a comment so I'm answering to close the question now that I have it figured out. Ultimately, the bug was most likely an issue with interleaved write calls and accessing the object's data. I've re-written...

Boost http server example not working?

c++,http,boost,boost-asio,server

If you are getting an HTTP response with status code of 404, then the HTTP server is running, handling the request, and serving a response. If the server was not running, then an HTTP response would not be returned. The browser may provide additional details about the failure: $ lsof...

cancel a deadline_timer, callback triggered anyway

c++,c++11,boost,callback,boost-asio

First, let's show the problem reproduced: Live On Coliru (code below) As you can see I run it as ./a.out | grep -C5 false This filters the output for records that print from C1's completion handler when really c1_active is false (and the completion handler wasn't expected to run) The...

How should I find which client I am receiving from in Boost Asio in UDP?

c++,sockets,boost,boost-asio

The application code is responsible for demultiplexing. At a high-level, there are two options: Use a single endpoint to conceptually function as an acceptor. Upon receiving a handshake message, the client would instantiate a new local endpoint, and inform the client to use the newly constructed endpoint for the remainder...

asio socket, inside a class declaration, scope issue

boost,boost-asio

You've declared socketTCP as a local variable in the constructor, not a member variable of the class. That means you can't use it in other functions. Presumably you meant to declare a member variable, and initialize that in the constructor instead of a local variable....

Boost::asio asynchronous connection timeout setting

c++,linux,boost,boost-asio

Since you are receiving data, you may want to set: SO_RCVTIMEO instead of SO_SNDTIMEO Although mixing boost and system calls may not produce the expected results. For reference: SO_RCVTIMEO Sets the timeout value that specifies the maximum amount of time an input function waits until it completes. It accepts a...

Boost.Asio, two readings by the same socket

c++,sockets,boost,boost-asio

async_read is guaranteed to cause exactly one call of the handler. You must not call async_read again until this handler has been called. question: are you running the io_service in multiple threads? If so, you'll need to pass your handler through an asio::strand. ...

Boost: Re-using/clearing text_iarchive for de-serializing data from Asio:receive()

c++,serialization,boost,deserialization,boost-asio

No there is not such a way. The comparison to MemoryStream is broken though, because the archive is a layer above the stream. You can re-use the stream. So if you do the exact parallel of a MemoryStream, e.g. boost::iostreams::array_sink and/or boost::iostreams::array_source on a fixed buffer, you can easily reuse...

Read message in its entirety with Boost.ASIO [WebSocket]

c++,boost,websocket,boost-asio

Looking at the websocket spec here: http://datatracker.ietf.org/doc/rfc6455/?include_text=1 you are on the right track. Use async_read_until to handle the handshake as it has undefined length but is delimited the same as http, and then, personally for exchange of the actual data after completing the handshake, switch to using async_read using either,...

What is the impact of calling io_service::run method twice

c++,boost,boost-asio

Your assumptions are correct. Each thread which calls io_service::run() will dequeue and execute handlers (simple function objects) in parallel. This of course only makes sense if you have more than one source of events feeding the io_service (such as two sockets, a socket and a timer, several simultaneous post() calls...

Stopping async_connect

c++,sockets,boost,boost-asio

There's nothing elementary wrong with the code, and it does exactly what you desire on my Linux box: TCP Connection in progress Connection not established... Trying to close socket... TCP Connection failed real 0m3.003s user 0m0.002s sys 0m0.000s Notes: You may have success adding a cancel() call to the stop()...

Correct syntax to assign unique_ptr to new boost::asio::io_service::work object?

c++,syntax,boost-asio,unique-ptr

Use unique_ptr::reset: keepAlive.reset(new boost::asio::io_service::work(IO_Service)); It's valid to use a unique_ptr for deferred construction, although it would be more ideal to use std/boost optional unless you also explicitly need/want to dynamically allocate it. I'll also note that you should attempt to design your classes so that you can fully construct everything...

Clarification on the use of `boost::bind` and `this`

c++,boost,boost-asio

boost::asio::placeholders::error is just like using boost::placeholders::_1 with boost::bind, and when you pass a bind expression containing that to an asio completion handler function, the function will invoke your handler with the boost::system::error_code result from the operation it performed, thus allowing your handler access to the error code. In your second...

Boost raw sockets

udp,boost-asio,icmp

boost::asio::ip::icmp::socket is a raw socket. The ip::icmp type encapsulates flags and types used for ICMP. In particular, the implementation of ip::icmp::type() returns SOCK_RAW: /// Obtain an identifier for the type of the protocol. int type() const { return BOOST_ASIO_OS_DEF(SOCK_RAW); } As icmp::socket's protocol type is raw, the ICMP example will...

Calculating the sum of a large vector in parallel

c++,multithreading,algorithm,parallel-processing,boost-asio

Is Boost.Asio suitable for this problem? The main purpose of Boost.Asio is to provide an asynchronous model for network and I/O programming, and the problem you describe does not seem to have much to do with networking and I/O. I think that the simplest solution is to use the threading...

Boost async server buffer error

c++,boost,boost-asio

You missed the include #include <boost/array.hpp> The toupper loop is wrong ((&sendBuffer)[i]) = toupper((&receiveBuffer)[i]); should be more like ((*sendBuffer)[i]) = toupper((*receiveBuffer)[i]); or even more like std::transform(receiveBuffer->begin(), receiveBuffer->end(), sendBuffer->begin(), static_cast<int(&)(int)>(std::toupper)); Pro tip: consider using unsigned char in the buffer to avoid unwanted sign extension when passing int to_upper ((*sendBuffer)[i]) =...

boost.asio: Accept IPv4 and IPv6 together

c++,networking,boost,boost-asio

If you create a IPv6 acceptor, it will accept both IPv4 and IPv6 connections if IPV6_V6ONLY socket option is cleared. IPv4 addresses will be presented as IPv6 addresses, in the IPv4-mapped format. Problems arise mainly around whether IPV6_V6ONLY is available or what the default value is (turned on or off)....

boost asio post not working , io_service::run exits right after post

c++11,boost,boost-asio

You don't actually post any work to the service. You start a thread that may eventually post work, but the main thread has already exited by that time. Either, run the ioservice on the thread or make sure it has io_service::work Here's a fix with a dedicated service thread and...

boost::asio read/write trouble

c++,boost,boost-asio

You get the end of file condition because the remote end of the connection closed or dropped the connection. You should be handling the system errors, or using the overloads that take a reference to boost::system::error_code. How else would you ever terminate the infinite loop? Live On Coliru #include <boost/asio.hpp>...

C++ , return string from function; boost::asio read / write

c++,string,boost,boost-asio

The most generic way would be use a asio::streambuf streambuf sb; size_t transferred = read (port, sb, ec); According to the docs: This function is used to read a certain number of bytes of data from a stream. The call will block until one of the following conditions is...

variadic boost bind type resolution

c++,templates,bind,boost-asio,variadic-templates

My suggestion for the function you ask about: template <typename T, typename... Args> void enqueue(T &t, Args const&... args) { this->io_service->post([=]{ auto s = stringer(t, args...); //std::fprintf(stderr, "%s\n", s.c_str()); }); } This works with GCC and Clang (GCC 4.9 or later because of a known issue with captured variadic packs)....

Boost::Asio - read or read_until?

c++,boost-asio

One is not better than the other. You use what your protocol requires. Typically binary protocols specify the packet length up front (by sending it first) text protocols tend to structure information using delimiters (like { ... } for JSON like grammars, or \r\n for SMTP/HTTP etc). Naturally you'd use...

Handle websocketpp connection path

c++,c++11,websocket,boost-asio,websocket++

Well, i found soultion by myself :) You should use following code for that purpose: server::connection_ptr con = s.get_con_from_hdl(hdl); std::string path = con->get_resource(); ...

How should I pass a boost::asio::yield_context in my own functions?

c++,c++11,boost,boost-asio,coroutine

It makes a lot of sense that the context has a lifetime that corresponds to that of the coroutine itself. This means, I anticipate it containing a pointer (or reference_wrapper) to the actual (hidden) implementation state. That said, simply do as the Boost library itself does, which is to take...

Can't use asio::placeholders::error in non-Boost version of Asio

c++,c++11,boost,boost-asio

In short, use std::placeholders::_1 instead of asio::placeholders:error. Asio only supports the convenient placeholder variables when using Boost.Bind. The error placeholder documentation states: An argument placeholder, for use with boost::bind(), ... When using std::bind() to create handlers, one needs to use std::bind's placeholders. The async_accept() operation accepts a handler that meets...

Getting the IP address of a received message in boost

c++,boost-asio

You can do so using the boost::asio::ip::udp::socket::async_receive_from() or boost::asio::ip::udp::socket::receive_from() functions, which have the endpoint_type & sender_endpoint output parameter. The returned endpoint can be used to resolve the sender IP address. ...

Multiple Http Servers with Poco and Boost C++

c++,boost-asio,poco,poco-libraries

HttpServerApplication is not designed to be used in this way. It's designed to be a singleton. http://pocoproject.org/docs/Poco.Util.ServerApplication.html You can fix that part by not deriving from ServerApplication in your HttpServer class. After all, you want multiple servers, not applications. In my simplest test, the following works: #include <Poco/Net/HTMLForm.h> #include <Poco/Net/HTTPRequestHandler.h>...

boost asio TCP server must bind to an IP address?

c++,boost,tcp,boost-asio

Bind to 0.0.0.0. That's the "wildcard" that listens on all interfaces for any incoming connection. If you bind to 127.0.0.1, your server will only accept incoming connections over the loopback, which won't let you client connect (since your client isn't using the loopback)....

Boost asio for multiple asynchronous network client operations

c++,multithreading,boost-asio

Here's a rough outline of what you need to do: First note that io_service.run() will return immediately if it has no work to do. So depending on your workflow you may need to defer calling it until you actually have the first asynchronous connect queued up. If you look at...

ConnectNamedPipe and asio overlappped ptr

c++,windows,boost-asio,named-pipes

Found the issue. I've not associated pipe with IOCP itself in server part. It can be done by wrapping pipe native handle returned by CreateNamedPipeA into boost::asio::windows::stream_handle just before calling ConnectNamedPipe. typedef boost::asio::windows::stream_handle StreamHandler; std::shared_ptr<StreamHandler> streamHandler = std::make_shared<StreamHandler>(*mIoService); streamHandle->assign(pipe); ...

Where can I download a ca.pem file for boost::asio::ssl?

c++,ssl,boost,boost-asio

You can use Mozilla certificate pack converted to PEM format by the authors of cURL library. You can download it from cURL site. I tried to run this boost.asio example using this pack and it ran successfully....

Boost.Asio TCP moved-to socket destructor not enough to cleanly close?

c++,sockets,boost,boost-asio

The code only creates a single socket, which is an automatic variable whose lifetime will end once main() returns. std::move(socket) only returns an xvalue that can be provided to socket's move constructor; it does not construct a socket. To resolve this, consider changing the callback() signature to accepting the socket...

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

c++,c++11,boost,boost-asio

The error message indicate that std::bind() cannot determine which io_service::run() overload to use: std::size io_service::run(); std::size io_service::run(boost::system::error_code&); For this particular case, Boost.Bind does not have an issue, but it does provide some troubleshooting for binding an overloaded functions. It recommends either casting: std::bind( static_cast<std:size_t (boost::asio::io_service::*)()>(&boost::asio::io_service::run), &ioService); Or using a temporary...

Error while using Boost Asio

c++,boost,mingw,boost-asio,codeblocks

So, I fixed this error by adding "-D_WIN32_WINNT=0x0501 -DWINVER=0x0501" to both compilers linker options (in C::B) and #defines. Guess I added _WIN32_WINNT somehow wrong.

Boost Exception Handling with Boost ASIO

c++,boost,boost-asio

The explanation you quote is somewhat misleading. Actually, io_service propagates any exceptions that escape from completion handlers, so it doesn't matter whether we use it for "user work" or for "asio functions" - in any case we might want to handle exceptions escaping from io_service::run (not only std::exception!). Consider the...

Boost Asio - Client to Server Strange output

asynchronous,boost,boost-asio

Well, I did it. When I read something, the data length was in the variable size_t length. So, from it, I did : if (!error) // If there is no error { for (int i = 0; i < (length); i++) // If i < length { std::cout << m_data[i];...

issues about using async_write right after async_read_until

boost-asio,asyncsocket

The async_write() overload being used is considered complete when all of the streambuf's data, its input sequence, has been written to the WriteStream (socket). It is equivalent to calling: boost::asio::async_write(stream, streambuf, boost::asio::transfer_all(), handler); One can limit the amount of bytes written and consumed from the streambuf object by calling this...

Permission refused when connecting to domain socket created by Boost.Asio

c++,sockets,c++11,boost-asio,socat

The issue is most likely the lifetime of the acceptor. The acceptor is an automatic variable in the DomainListener constructor. When the DomainListener constructor completes, the acceptor is destroyed, causing the acceptor to close and cancel outstanding operations, such as the async_accept operations. Cancelled operations will be provided an error...

Does boost asio io_service guarantee execution of two parallel call chains?

c++,boost,boost-asio

The io_service currently makes no guarantees about the invocation order of handlers. Thus, the io_service could choose to invoke only a single call chain. Currently, only a strand specifies guarantees. With that said, I would not worry too much about the io_service currently not making the guarantee. As Asio is...

set_option: Invalid argument when setting option boost::asio::ip::multicast::join_group inside lambda

c++11,boost,boost-asio,multicast

There is a race condition that can result in dangling references being accessed, invoking undefined behavior. The lambda capture-list is capturing the automatic variables, multicast_address and portNumber, by reference. However, the lifetime of these objects may end before their usage within _io_service_thread: void doIO() { const boost::asio::ip::address multicast_address = /*...

Cancelling callbacks in Boost ASIO

multithreading,sockets,c++11,boost,boost-asio

The program is invoking undefined behavior when the server thread attempts to unlock the read_lock that it does not own. int main() { ... std::mutex read_mutex; std::unique_lock<std::mutex> read_lock(read_mutex); // Acquired by main. std::condition_variable read_done; std::thread server([&]() { // Capture lock reference. std::unique_lock<std::mutex> lock(mutex); ... // The next line invokes undefined...

Executing asynchronous operations within the same strand

c++,multithreading,sockets,asynchronous,boost-asio

If access to the stream object is controlled by a mutex, making sure that only one thread operates on the ssl stream at a given time, what is the need for using an implicit/explicit strand? There is no need then. The mutex makes the operations serialize as on a...

boost asio custom allocator handler io service post compile errors

c++,templates,boost,bind,boost-asio

To be compatible with CompletionHandler object returned by makeCustomAllocHandler should define void operator()() instead of void operator()(const boost::system::error_code&, std::size_t) required by ReadHandler and used in server example.

boost::asio how to read full buffer in right way?

c++,boost,boost-asio

From the read_some reference: This function is used to read data from the stream socket. The function call will block until one or more bytes of data has been read successfully, or until an error occurs. With remarks: The read_some operation may not read all of the requested number of...

iostream and No_delay option

tcp,boost-asio

Where you set the option, the stream is still invalid (not open). Wait until the socket is open, before setting the option: Live On Coliru #include <boost/asio.hpp> #include <iostream> static boost::asio::ip::tcp::no_delay const no_delay_option (true); int main() { using boost::asio::ip::tcp; tcp::iostream socketStream; boost::asio::io_service io_service; tcp::endpoint endpoint (tcp::v4(), 6666); tcp::acceptor acceptor (io_service,...

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

c++,boost,debian,boost-asio,keypad

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 <boost/bind.hpp> #include <iostream> // for debug output #include <iomanip> #include <linux/input.h> // for input_event #include <boost/range/adaptor/sliced.hpp> #include <boost/date_time/posix_time/posix_time.hpp> using namespace boost::asio; struct input { using...

Boost async sockets and thread pool on same io_service object

c++,multithreading,sockets,boost,boost-asio

Neither. Each async_read operation is initially handled by the thread that called it. If forward progress can't be made without the socket being ready (because the other side needs to send or receive something), the async operation returns to the calling thread. Socket readiness is monitored by the "reactor", an...

Create timer with boost::asio

c++,boost,boost-asio

Update I get it. You want dynamically allocated timers? Live On Coliru #include <boost/asio.hpp> #include <boost/make_shared.hpp> using namespace boost; using Timer = shared_ptr<asio::deadline_timer>; asio::io_service _io; void handler(int a, const system::error_code& = {}, Timer timer = make_shared<Timer::element_type>(_io)) { std::cout << "hello world\n"; timer->expires_from_now(posix_time::seconds(1)); timer->async_wait(bind(handler, a, asio::placeholders::error, timer)); } int main() {...

Concurrent read and async_read_some in boost asio

c++,sockets,boost-asio

Boost.Asio does not make this guarantee on any I/O object. When a synchronous operation is initiated on an I/O object that has an outstanding asynchronous operation of the same type, the order in which the underlying system calls occur is unspecified.

Intermittent issues with SSL, using Boost/Asio

c++,multithreading,ssl,openssl,boost-asio

This issue was caused by bug in the Asio SSL implementation. Reported it to the Asio Github issue tracker. When an error occur in OpenSSL, errors-codes are pushed onto a queue. A single call to OpenSSL may result in multiple error-codes being pushed to the queue. For example, a low-level...

boost async operations not working (for me)

c++,asynchronous,boost,boost-asio

The problem is that the deadline_timer object needs to stay alive until the handler triggers, otherwise the handler will be triggered instantly with an error when is.run() is called. The timer is being destroyed when the async_rotateLeftFor function exits. What I do to keep the timer around, is wrap the...

boost::asio sync server is not accepting connections after first one

c++,boost-asio

The general pattern for an asio-based listener is: // This only happens once! create an asio_service create a socket into which a new connection will be accepted call asio_service->async_accept passing the accept socket and a handler (function object) [ see below] start new threads (if desired. you can use the...

Serializing mutable state and sending it asynchronously over the network with nearly-zero-copy (Cap'n Proto + ZeroMQ)

c++,serialization,boost,boost-asio,zeromq

I do not know much about ZeroMQ's interface but I can give advice on how to minimize copies from Cap'n Proto. On the sending side, use capnp::MessageBuilder::getSegmentsForOutput() (capnp/message.h) to get direct pointers to the message's content without copying. This gives you an array of arrays of bytes (actually, words, but...