FAQ Database Discussion Community


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

c++,linux,boost,boost-asio
I have a small program that makes an SSL connection to a server and then copies data from STDIN to the server and data from the server to STDOUT (much like openssl s_client). I'm using boost::asio for reading and writing to STDIN, STDOUT and the SSL socket. The problem is...

Boost raw sockets

udp,boost-asio,icmp
I know it is a very theoretical question, but forgive me as this is not my specialty. Looking for an example on how to use raw sockets with boost, I found a question in this same website where it is assured that you cannot know the destination of an UDP...

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

c++,debugging,boost,gdb,boost-asio
I have strange behaviour in server program. In simple example it works fine (I insert traces everywhere, in pion and asio). #include <pion/http/server.hpp> #include <pion/http/response_writer.hpp> #include <pion/http/response_reader.hpp> #include <pion/http/request_writer.hpp> #include <pion/logger.hpp> #include <pion/scheduler.hpp> int main() { pion::single_service_scheduler shed; shed.set_num_threads(1); boost::shared_ptr<pion::http::server> server (new pion::http::server(shed, 5000));...

dispatch response packet according to packet sequence id

c++,boost,boost-asio
I have a third-part server, and I'm writing a dll interface for it, my clients use my dll to communicate with the server. The protocol uses a long tcp connection, all traffic goes from this tcp connection. There could be sending/receiving multiple packets at the same time, like a send_msg...

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

c++,serialization,boost,deserialization,boost-asio
This is my current function that de-serializes data received via Boost:Asio UDP transmission. It works perfectly, however the performance is pretty bad. About 4000 or so calls per second will use ~16% of CPU, which is a full thread of an I7. Running a performance test on the code shows...

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

boost,handler,boost-asio
I am struggling with compile time errors, and try as I might, I dont see in what way am I doing it wrong or different from handler function signature as set out in documentation/examples. (I am using Boost 1.41 on Linux) Please help me understand the error! (included below as...

Does BOOST asio supports eventfd? like epoll

c++,boost,boost-asio
epoll() can do its poll on lots of fd types such as normal fd, sockets, timefd, eventfd, etc... Can BOOST do it also somehow? I saw in io_service that it supports only: The io_service class provides the core I/O functionality for users of the asynchronous I/O objects, including: boost::asio::ip::tcp::socket boost::asio::ip::tcp::acceptor...

Getting started with network programming in Qt [closed]

c++,qt,network-programming,boost-asio
I just started a summer job at my university doing work in a lab, and I've been given a rather large, vague problem to tackle without much guidance so I was hoping someone could help point me in the right direction. Essentially it's a 3-d world built in Qt using...

Boost.Asio, two readings by the same socket

c++,sockets,boost,boost-asio
I'm learning Boost.Asio. I have defined a class that has the role of client and server: I can create connections, send requests and receive responses (client role). I can accept requests and send responses to those requests (server role). I can also create subscriptions: Creates a connection, it sends a...

Multiple Http Servers with Poco and Boost C++

c++,boost-asio,poco,poco-libraries
I'm trying to create multiple Http servers with Poco::Net and Boost libraries, but is occurring the following error internally in Poco file Application.cpp: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Assertion violation: _pInstance == 0 [in file "src/Application.cpp", line 115] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% I'm using the code below: #include <Poco/Net/HTMLForm.h> #include <Poco/Net/HTTPServerRequest.h> #include <Poco/Net/HTTPServerResponse.h> #include <boost/asio/io_service.hpp> boost::asio::io_service...

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

c++,sockets,c++11,boost-asio,socat
I'm trying to create a server that receives connections via domain sockets. I can start the server and I can see the socket being created on the filesystem. But whenever I try to connect to it via socat I get the following error: 2015/03/02 14:00:10 socat[62720] E connect(3, LEN=19 AF=1...

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

c++,boost,websocket,boost-asio
I'm writing a simple WebSocket server using Boost.ASIO. Right now, I'm working on trying to process the handshake. My problem is, it doesn't look like there's a predefined length for handshake messages sent from the client. My question is, how can I stop reading the handshake when the message ends?...

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

c++,boost-asio
I am writing simple synchronous asio server. Workflow is following - in endless cycle accept connections and create thread for each connection. I know, this is not so optimal, but async is too hard for me. Here's my ugly code: std::vector<asio::io_service*> ioVec; std::vector<std::thread*> thVec; std::vector<CWorker> workerVec; std::vector<tcp::acceptor*> accVec; while (true)...

issues about using async_write right after async_read_until

boost-asio,asyncsocket
My code is as follows: boost::asio::streambuf b1; boost::asio::async_read_until(upstream_socket_, b1, '@', boost::bind(&bridge::handle_upstream_read, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); void handle_upstream1_read(const boost::system::error_code& error, const size_t& bytes_transferred) { if (!error) { async_write(downstream_socket_, b2, boost::bind(&bridge::handle_downstream_write, shared_from_this(), boost::asio::placeholders::error)); } else...

boost::asio::serial_port and RTS pin

c++,boost,serial-port,boost-asio
I would like to control an instrument operation by using a c++ program. How do I use boost asio library to set the RTS pin to logical true or logical false? This is for a RS-232 serial port....

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

c++,c++11,tcp,boost-asio
The server accept new connections : void do_accept() { acceptor_.async_accept(socket_, [this](boost::system::error_code ec) { if (!ec) { connection_count++; all_session.push_back(std::make_shared<session>(std::move(socket_), io_service_)); all_session.back()->start(); } do_accept(); }); } and the session->start works like below: void start() { std::cout << "connection from " << socket_.remote_endpoint().address() << std::endl; do_read_header(); } the do_read_header tackle the messages then...

boost asio custom allocator handler io service post compile errors

c++,templates,boost,bind,boost-asio
I have working io_service post call that looks as follows: _io_service.post(std::tr1::bind(&BlitzLogger::push,this, std::tr1::bind(&BlitzLogger::stringer<typename boost::decay<T const &>::type, typename boost::decay<Args const &>::type ...>, this, t, args ...))); I suspect the bind calls are having some overhead that can be done away with, so I proceeded to lay out the custom allocators for handlers...

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

c++,boost,boost-asio
In example: http://www.boost.org/doc/libs/1_45_0/doc/html/boost_asio/example/chat/chat_server.cpp we always create new pointer to accept new session. If we don't, server will shutdown (in case of error). My server has a limit set of IDs and each session gets one. So when set is empty server can't respond to new session until one of IDs...

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

c++,encryption,aes,boost-asio,crypto++
I am developing an encrypted version of a realtime communication application. The issue I have is, that the encrypted data pakets sent to the receiver are faulty. An example from the error log: (hex encoded data, the original data is pure byte code). sent: 262C1688215232656B5235B691826A21C51D37A99413050BAEADB81D8892493FC0DB519250199F5BE73E18F2703946593C4F6CEA396A168B3313FA689DE84F380606ED3C322F2ADFC561B9F1571E29DF5870B59D2FCF497E01D9CD5DFCED743559C3EE5B00678966C8D73EA3A5CD810BB848309CDF0F955F949FDBA618C401DA70A10C36063261C5DBAB0FC0F1...

Boost::asio asynchronous connection timeout setting

c++,linux,boost,boost-asio
Below is my code boost::asio::io_service io; boost::asio::ip::tcp::acceptor::reuse_address option(true); boost::asio::ip::tcp::acceptor accept(io); boost::asio::ip::tcp::resolver resolver(io); boost::asio::ip::tcp::resolver::query query("0.0.0.0", "8080"); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); accept.open(endpoint.protocol()); accept.set_option(option); accept.bind(endpoint); accept.listen(30); boost::asio::ip::tcp::socket ps(io); accept.accept(ps); struct timeval tv; tv.tv_sec = 1; tv.tv_usec = 0;...

Boost async sockets and thread pool on same io_service object

c++,multithreading,sockets,boost,boost-asio
I am writing a server application. For multi threading I using a thread pool similar to this one. In the network interface I use sockets with async operations. All sockets and the thread pool use the same io_service object. My question is do async_read operations on multiple sockets "block" a...

variadic boost bind type resolution

c++,templates,bind,boost-asio,variadic-templates
I'm trying to write an async logger which accepts variadic arguments that are then strung together using a variadic stringer and then pushed onto a single producer single consumer queue. I'm stuck in my enqueue function part of my Log struct which looks as follows: template <typename T> std::string Log::stringer(T...

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

c++,linux,boost-asio
I'm a beginner in boost::asio. I need to code a module which reads from a pipe and puts the data into a ring buffer (I've no problem in how to implement this part). Another part of the module waits for a consumer to open a new TCP connection or unix...

Passing a unique_ptr reference to boost::bind?

c++,gcc,boost,boost-asio,boost-bind
I'm on CentOS 6.6 (gcc 4.4.7) and developing with Boost.Asio (1.41). I'd like io_service to call member function run() in manger object m when it starts. The code I'm trying to compile looks like: #include <memory> #include <boost/asio.hpp> #include <boost/bind.hpp> boost::asio::io_service io; std::unique_ptr<manager> m; m = std::make_unique<manager>; io.post(boost::bind(&manager::run, &m)); gcc...

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

c++,json,boost-asio
I have written following program to GET a JSON response from the server. The code is correct and the response from the server is as per my expectation. #include <boost/asio/ip/tcp.hpp> //I have not shown some header for sake of readability int main () { try { boost::asio::ip::tcp::iostream s; s.expires_from_now(boost::posix_time::seconds(60)); const...

boost::asio read n bytes from socket to streambuf

c++,boost,boost-asio,boost-serialization,streambuf
I have got a serialized structure, which is being send via socket. I need to read it by chunks, since one of its fields contain size of data remaining, so I need to read first few bytes, find out the length and read the rest. This is what I have...

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

c++,c++11,boost,boost-asio
From Asio documentation The run() function blocks until all work has finished and there are no more handlers to be dispatched, or until the io_service has been stopped. In the following snippet Asio has no work apart from debug output (which is instantly computed), but run() does not return. #define...

Boost asio for multiple asynchronous network client operations

c++,multithreading,boost-asio
I want to use boost::asio (or asio stand alone) to query multiple network devices once a minute for data via asynchronous sockets. For a test I have already implemented a Client class and a console program that does that for one device (without repetition). Something like this: class MyClient {...

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

c++,c++11,boost,boost-asio,move-constructor
I think in the following code should work but it generates a compilation error: error C2248: 'boost::asio::basic_io_object<SocketService,true>::basic_io_object' : cannot access private member declared in class 'boost::asio::basic_io_object<SocketService,true>' It seems that the move constructor is not called implicitly. #include <thread> #include <boost/asio.hpp> void Func(boost::asio::ip::tcp::socket sock) {} int main() { boost::asio::io_service service; boost::asio::ip::tcp::socket...

Cancelling callbacks in Boost ASIO

multithreading,sockets,c++11,boost,boost-asio
I've been trying to switch my code from using one io_service per network connection to using shared ones, and I'm seeing some very odd behaviour on server sockets (client ones seem to work OK). In order to try to work out what's going on I've re-started building up a simple...

C++ lambda, not seeing function and argument?

c++,multithreading,c++11,lambda,boost-asio
I have some code using a wrapper class around std::thread, which is using a timer struct (based upon boost::asio), to call methodToCallEachIteration() every 5000 milliseconds: class OurThreadWrapperClass{ OurThreadWrapperClass(boost::asio::io_service& = generic_timer_queue_s()); }; class A { A() : thread1(_TimerIOService){ thread1.setInterval(5000); // This sets the callback function, to be called every INTERVAL ms....

Resuming asio coroutine from another thread

c++,multithreading,boost-asio
I have a problem with resuming boost::asio coroutine from another thread. Here is sample code: #include <iostream> #include <thread> #include <boost/asio.hpp> #include <boost/asio/steady_timer.hpp> #include <boost/asio/spawn.hpp> using namespace std; using namespace boost; void foo(asio::steady_timer& timer, asio::yield_context yield) { cout << "Enter foo" << endl; timer.expires_from_now(asio::steady_timer::clock_type::duration::max()); timer.async_wait(yield); cout << "Leave foo" <<...

Concurrent read and async_read_some in boost asio

c++,sockets,boost-asio
Assume that an async_read_some service has been enabled on a socket in boost::asio, what will happen if a blocking read on the same socket is called? A piece of pseudo code looks like: using boost::asio::local::stream_protocol; boost::asio::io_service io; stream_protocol::socket s(io); s.connect(stream_protocol::endpoint(address)); s.async_read_some(aBuffer, aCallback); // start async_read boost::thread thread(boost::bind(&boost::asio::io_service::run, &io)); usleep(1000000); //...

SSL certificates and Boost asio

c++,boost,openssl,boost-asio
Hello I'm trying to download content from webpage that uses https via C++. My very basic client program taken from the Boost asio examples compiles and runs fine, but when I test it eg with Google: www.google.co.uk/?gws_rd=ssl, it gives me the error "handshake: certificate verify failed". I think this is...

Using the same Boost.Asio io_service for accepting tcp connections synchronously and as a thread pool

c++,c++11,boost,boost-asio
Is the following method of using io_service for accepting tcp connections and also as a thread pool for serving connected clients valid, or is there some caveat? io_service svc; io_service::work work(svc); // define the three threads in the io_service thread pool thread t1( [&svc]() { svc.run(); } ); thread t2(...

Boost Asio, async UDP client - crash on shutdown

c++,boost,boost-asio
I use UDP client-server for IPC in my application It works fine, but when trying to shutdown the client side some race condition happen, which causes application crash or deadlock. UDP client: // IOServiceBase class contain boost::asio::io_service instance // it is accessible by service() protected method class AsyncUDPClient : public...

Setting option SO_SETFIB on boost sockets

sockets,boost,boost-asio
I do not see any option to set SO_SETFIB on boost sockets. Anyone has any idea or point me in right direction how to achieve that?

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

c++,linux,sockets,boost,boost-asio
I have a Linux service (daemon) that has multiple-threads and uses boost io_service listening on a TCP socket. When I receive a certain message on that socket I want to start another service with e.g. /etc/init.d/corosync start. The problem is that after starting the service, when I quit my own...

Getting the IP address of a received message in boost

c++,boost-asio
How can I retrieve the IP address with boost when I receive a UDP message(using boost::asio::ip::udp)? Thanks!...

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 have an application in which I'd like to send part of its mutable state over the network to another machine (there will be a cluster of those machines) to do some CPU-intensive computations on it and get back the results. Like asynchronous RPC. Such calls will happen many times...

Error while using Boost Asio

c++,boost,mingw,boost-asio,codeblocks
I get "::UnregisterWaitEx is not declared" inside win_object_handle_service.ipp whenever I try to include < boost/asio.hpp > into my code. Currently I am using Code::Blocks, MinGW compiler (which didn't come bundled with IDE) on Windows 8.1. Boost is built outside of mingw include folder, though is included in project settings. Exact...

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

c++,boost,boost-asio
I'm trying to write a wrapper method set_timer() that takes a time and callback (expressed using boost::bind) and sets up a deadline_timer to run that callback. The callback is real simple at the moment: void foo::callback(const boost::system::error_code& error) { std::cout << "callback" << std::endl; } For set_timer() I have: void...

Boost async server buffer error

c++,boost,boost-asio
I am trying to make a server & client in boost asio. Currently I am receiving this error. Can you point me what I am doing wrong? #include <boost/asio.hpp> #include <boost/bind.hpp> #include <boost/thread.hpp> // Forward declaration class ASyncConnectionMT; class ASyncEchoServerMT; // Typedef for the buffer type (shared_ptr) typedef boost::array <...

Boost http server example not working?

c++,http,boost,boost-asio,server
I have copied the files (the ones from the "HTTP Server") from this tutorial, but it seems that it is not working. I have run the application with 0.0.0.0 5000 ., but when I try to connect to the page localhost:5000 I get always 404 Not Found. What to do...

boost asio TCP server must bind to an IP address?

c++,boost,tcp,boost-asio
I am not sure whether I am using BOOST ASIO properly, my code is as follows, boost::asio::ip::tcp::resolver resolver(io_); boost::asio::ip::tcp::resolver::query query(std::string("127.0.0.1"), port); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); acceptor_.open(endpoint.protocol()); It binds to 127.0.0.1. When a client is connecting externally, the client is using the IP address 192.168.0.107 or something similar. The server implemented...

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

c++,sockets,boost,boost-asio
Consider this test program : #include <boost/asio/io_service.hpp> #include <boost/asio/ip/tcp.hpp> #include <functional> #include <iostream> static void callback (boost::asio::ip::tcp::socket && socket) { //boost::asio::ip::tcp::socket new_socket = std::move(socket); std::cout << "Accepted" << std::endl; } static void on_accept (boost::asio::ip::tcp::acceptor & acceptor, boost::asio::ip::tcp::socket & socket, boost::system::error_code const & error) { if (error) { std::cerr << error...

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

c++,c++11,boost,boost-asio
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 everything is fine. Here's code: #include <iostream> #include <memory> #include <thread> #include <functional>...

How to use boost::asio with Linux GPIOs

c++,boost-asio,gpio,epoll
I have a single-threaded Linux application using boost::asio for asynchronous input/output. Now I need to extend this application to read in GPIO inputs on /sys/class/gpio/gpioXX/value. It is possible to do that with boost::asio::posix::stream_descriptor on edge-triggered GPIO inputs? I configured the GPIO input like follows: echo XX >/sys/class/gpio/export echo in >/sys/class/gpio/gpioXX/direction...

How to deal with extra characters read into ASIO streambuf?

c++,c++11,boost,boost-asio
Most libraries has parsers works only over std::istream or single continuous buffer. Those parsers read istream until the eof, not the end of document. Even if there is a nice boost::asio::streambuf, that can be used with istream, there is a problem with reading and committing only one frame to it....

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

c++,c++11,boost,boost-asio
I'm trying to use the non Boost version of Asio in a project. I'm writing a callback to stream_protocol::acceptor::async_accept. The signature requires asio::placeholders::error to be passed but when I do so, I get the following error: error: no member named 'error' in namespace 'asio::placeholders' Following the source, I can see...

boost::asio::async_read() of stream_descriptor now returning EOF

ubuntu,c++11,boost-asio,eof
Upgraded Ubuntu today from 14.10 to 15.04. Now seeing different behaviour either in boost::asio::async_read(), boost::asio::posix::stream_descriptor, or tap/tun interfaces. Calling async_read() immediately returns boost::asio::error::eof. If I ignore the error and loop back up to start a new async_read() it does eventually read when bytes are available, and the application continues to...

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

c++,linux,boost-asio
I have a custom signal that is emitted from a kernel module to user space in the following way. Note that I include an integer (id) in the si_int struct parameter attached to the signal, and I already know the pid of the user-space app I am targeting. struct siginfo...

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

c++11,boost,boost-asio,multicast
This code is intended to receive UDP multicast messages using Boost.Asio. A Boost system_error exception is thrown by the code below when the second set_option() call inside receiver's constructor is made (to join the multicast group). The complaint is "Invalid argument". This seems to be related to the fact that...

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

c++,syntax,boost-asio,unique-ptr
What's the correct syntax to assign a std::unique_ptr<boost::asio::io_service::work> pointer to a new boost::asio::io_service::work object? I am converting boost::asio code from using static functions and global variables to a class implementation, but this means I have to replace the working initialization: std::unique_ptr<boost::asio::io_service::work> KeepAlive( new boost::asio::io_service::work(TheASIOService)); with a class member variable in...

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

c++,boost,boost-asio
I'm using boost::asio::write() to write data from a buffer to a com-Port. It's a serial port with a baud rate 115200 which means (as far as my understanding goes) that I can write effectively 11520 byte/s or 11,52KB/s data to the socket. Now I'm having a quite big chunk of...

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

c++,boost,boost-asio
I am learning the boost::asio and now confusing about the right way to read the full buffer. For excample, when connection established I want to read int32 in next way: std::uint32_t size; size_t len = m_socket.read_some(buffer(&size, sizeof(std::uint32_t))); As you see I set up the buffer size. In other case I...

Boost::Asio - read or read_until?

c++,boost-asio
I'm learning to use Boost::Asio I was wondering : when should I use read_until ? When should I use read ? Is it better to specify the length of your data in a header at the beginning of your data buffer OR to use a delimiter with read_until ?...

What does boost::asio::spawn do?

c++,boost,boost-asio,boost-coroutine
I am unable to form a mental picture of how the control flow happens with spawn. When I call spawn(io_service, my_coroutine), does it add a new handler to the io_service queue that wraps a call to the my_coroutine? When inside the coroutine I call an async function passing it my...

Handle websocketpp connection path

c++,c++11,websocket,boost-asio,websocket++
I'm really newbie in websocketpp. Can you tell me please, how can i get websocket connection path on new connection in my server? I mean i need to get the part of this: ws://localhost:8080/addr1 ------> get addr1 ws://localhost:8080/addr2 ------> get addr2 ws://localhost:8080/etc ------> get etc I'm using now an example...

iostream and No_delay option

tcp,boost-asio
I am trying to disable the Nagle Algorithm using the answer for the same question: ASIO ip::tcp::iostream and TCP_NODELAY: boost::asio::ip::tcp::iostream socketStream; const boost::asio::ip::tcp::no_delay option( true ); socketStream.rdbuf()->set_option( option ); boost::asio::io_service io_service; tcp::endpoint endpoint (tcp::v4 (), 6666); tcp::acceptor acceptor (io_service, endpoint); std::cout << "Waiting for connection.." << std::endl; acceptor.accept (*socketStream.rdbuf ());...

How to know which version of openssl boost ssl is using

c++,openssl,boost-asio
I have some questions about boost openssl updation How can I find out which version of openssl boost ssl is using? Do we need to recompile the C++ boost application after updating openssl or will updating openssl suffice? ...

boost::asio read/write trouble

c++,boost,boost-asio
I started to learn the boost::asio and tried to make simple client-server application. At now I have troubles with server. Here it code: int main(int argc, char* argv[]) { using namespace boost::asio; io_service service; ip::tcp::endpoint endp(ip::tcp::v4(), 2001); ip::tcp::acceptor acc(service, endp); for (;;) { socker_ptr sock(new ip::tcp::socket(service)); acc.accept(*sock); for (;;) {...

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

c++,multithreading,boost,boost-asio,signals-slots
I'm trying to use a boost::lockfree queue to manage tasks. These tasks retrieve data and would be processed on a worker thread. Once data is retrieved, a signal should be sent to the main thread with the data. The worker thread is spawned at the start of the application and...