asio

Is there an elegant way to bridge two devices/streams in ASIO?

Given two stream-oriented I/O objects in Asio, what is the simplest way to forward data from one device to the other in both directions? Could this be done with boost::iostreams::combination or boost::iostreams:copy perhaps? Or is a manual approach better--waiting for data on each end and then writing it out to the other stream? In other...

Synchro boost example problem

Dear everybody, I have a problem using asio. My client/server application requires only synchronous communication. So, using the examples for synchro from the boost homepage, I have set up two procedures to send and receive data. Their code is as follows: void vReceive(tcp::socket & socket, std::string & szDest){ char szTmp_Buf [BUF...

boost::bind, boost::asio, boost::thread, and classes

sau_timer::sau_timer(int secs, timerparam f) : strnd(io), t(io, boost::posix_time::seconds(secs)) { assert(secs > 0); this->f = f; //t.async_wait(boost::bind(&sau_timer::exec, this, _1)); t.async_wait(strnd.wrap(boost::bind(&sau_timer::exec, this))); boost::thread thrd(&io,this); io.run(); //thrd(&sau_ti...

ASIO iostream flush not working?

any ideas why stream.flush(); won't work? boost::asio::ip::tcp::iostream stream("localhost","5000"); assert(stream.good()); stream << 1; stream.flush(); while(true); it's only flushed if the loop is removed and the line boost::this_thread::sleep(boost::posix_time::seconds(1)); is executed (much later). Thanks Update: I did some ...

Boost Threads and Timers, C++

I have this code for a custom class 'sau_timer': sau_timer::sau_timer(int secs, timerparam f, vector<string> params) : strnd(io), t(io, boost::posix_time::seconds(secs)) { assert(secs > 0); this->f = f; this->params = params; t.async_wait(strnd.wrap(boost::bind(&sau_timer::exec, this, _1))); boost::thread thrd(b...

How to resolve host (only) using Boost.Asio?

According to the documentation of boost::asio::ip::tcp::resolver::query in order to resolve host it should receive service as well. What if I want to resolve host without relation to port? How should I do it at all? Should I specify dummy port? ...

C++, boost asio, receive null terminated string

Hi, How can I retrieve null-terminated string from socket using boost::asio library? Thanks in advance ...

boost asio: maintaining a list of connected clients

I'm looking for the best way to modify the Boost Asio HTTP Server 3 example to maintain a list of the currently connected clients. If I modify server.hpp from the example as: class server : private boost::noncopyable { public: typedef std::vector< connection_ptr > ConnectionList; // ... ConnectionList::const_iterator GetC...

Boost asio udp waitForReadyRead

Hello, I am trying to implement a function using boost asio udpSocket, that waits until data is ready to be read, or waits until a timeout expires. using asyc_read and a async_wait, I can do something similar, but I have to read the data. I would like to do the same without reading the data This would allow a much easier use of the ud...

Boost::asio async_wait handler signature

Hi, I am going through the boost::asio examples. I am looking at Example 4 What is confusing is that, the WaitHandler in this example has the signature void print (this) But the async_wait call expects a handler whose function signature of the handler must be: void handler( const boost::system::error_code& error ...

asio sctp library support for PPI (Protocol Payload Identifier)

Hi I'm using the experimental asio sctp library. (code.halssoftware.com/index.php/p/boostasiosctp/source) It's pretty easy to use like the other networking stuff in asio. The one problem I have is that I want to use the PPI field in SCTP data chunks - but I can't figure out how to get that information from the asio sctp interface. It ...

boost asio io_service.run() question

I was just going over the asio example here: http://www.boost.org/doc/libs/1%5F39%5F0/doc/html/boost%5Fasio/example/chat/chat%5Fserver.cpp My question is about their usage of the io_serice.run() function. The documentation for the io_service.run() function says: "The run() function blocks until all work has finished and there are no mo...

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 a message-length and then writes a message, and then waits to read a message-length and ...

Detaching a native socket from Boost.ASIO's socket class

Is it possible to detach a native socket from Boost.ASIO's socket class? If so, how can it be done? I can't seem to find anything obvious in the documentation. As a quick overview of what I'm trying to accomplish: I have a class that makes a connection and does some negotiation using Boost.ASIO, then passes back a native Windows SOCKET ...

How can I get a callback when there is some data to read on a boost.asio stream without reading it into a buffer?

It seems that since boost 1.40.0 there has been a change to the way that the the async_read_some() call works. Previously, you could pass in a null_buffer and you would get a callback when there was data to read, but without the framework reading the data into any buffer (because there wasn't one!). This basically allowed you to writ...

Release socket in Boost.Asio (opposite of assign), or not transfer ownvership

Hello, There is a function assign in Boost.Asio sockets, however I'm looking for something like release/unassign that would transfer the ownership on socket back to user. or some type of assign that would not transfer ownership to socket class, so it would not close it when destroyed. I'm aware of this solution but it involves d...

Using Mysql blocking API with Boost::asio

I am building a aync single threaded server that receives data from clients. It processes the data and then saves it to the MySQL Database. The problem is that, MySQL C API does not support non-blocking calls and asio mainly does not like blocking calls. So I am thinking something like Python Twisted's deferToThread() like semantics. I...

Prevent memory pollution in web application (boost::asio).

well, I read data to buffer using read_until - it's easy to check it's size after that. What about aborting reading after excesses some defined limit of package length? PS Also std::string s((istreambuf_iterator<char>(someStreamBuf)), istreambuf_iterator<char>()); Doesn't work properly - it cuts part of last line (everyth...

extend boost.asio file i/o for linux

According to this question about the topic there is no asynchronous file io in asio anything but Windows... So fine, does anyone know of any already written extensions to asio that do asynchronous file io on Linux? Or does anyone know of any examples on how to extend asio to support asynchronous io to {insert-whatever-here}? ...

Boost asio io_service dispatch vs post

Can anyone tell me the difference between io_service dispatch and post? It was not clear to me what is more suitable for my problem. I need to invoke a handler inside another handler and I don't what invoker to use. Thanks. ...