I'm creating a logger which, instead of writing to file, stdout, or stderr, writes to a socket so that it can be logged by a separate process (or on a separate machine).
The trick is that this logger runs in a time-sensitive real-time scheduler. Therefore I cannot wait for the OS to block my process during sending operations. Boost's asio library looks like a good option.
My problem is using the bind function on line 23. The intention is:
io_service.post() will execute the argument function in the thread which "run" has been invoked. I want to run: m_socket.send(message) in that thread. To do that, I am using boost bind with the arguments shown in line 23, but I think I have a syntax issue. Any ideas would be appreciated.
$ g++ -o client main.cpp -L/usr/lib -lboost_thread -lboost_system
In file included from logger.h:3:0,
from main.cpp:1:
streamsender.h: In member function ‘void StreamSender::Send(const string&)’:
streamsender.h:25:14: error: no matching function for call to ‘bind(<unresolved overloaded function type>, boost::asio::ip::tcp::socket*, const boost::arg<1>&)’
_1)(boost::asio::buffer(message)));
^
This is funny because straight from Boost's website they give this as an example of how to use boost::bind:
$ g++ -o client main.cpp -L/usr/lib -lboost_thread -lboost_system
In file included from logger.h:3:0,
from main.cpp:1:
streamsender.h: In member function ‘void StreamSender::Send(const string&)’:
streamsender.h:28:82: error: invalid use of void expression
m_io_service.post(boost::bind(&StreamSender::transmit, this, _1)(message));
^