boost-asio

Alternative to missing method in last version of Boost asio library

三世轮回 提交于 2020-01-06 04:30:12
问题 Some years ago, I wrote a email client using Boost asio library. There are a abstract class ICON with four subclasses. POP3conN to flat POP3 communications POP3conS to secure POP3 communications SMTPconN to flat SMTP communications SMTPconS to secure SMTP communications ICON has a member boost::asio::ip::tcp::socket socket_ and two virtual procedures, defined in echa subclass: void SMTPconN::run() { socket_.get_io_service().run(); } void SMTPconN::reset() { socket_.get_io_service().reset(); }

C++ ASIO: async_accept() handler throws exception when server destroys

谁说我不能喝 提交于 2020-01-06 03:56:06
问题 I am developing a C++ ASIO based application. Referring to Chat Server My Server Class: class CServer { public: CServer(asio::io_service& io_service, const std::string serIdentity, std::string IP, const std::string port); ~CServer(); void listen(); void handle_accept(sessionPtr newSession, const asio::error_code& error); private: tcp::acceptor acceptor_; // only in the listener asio::io_service& io_; CSerSessionsManager mng_; }; void CServer::listen() { sessionPtr newSession = std::make

Windows 7 MinGW compilation error using Boost ASIO

时间秒杀一切 提交于 2020-01-05 09:30:49
问题 Having trouble compiling the following C++ code on Windows 7: #include <boost/asio.hpp> #include <iostream> void handler1(const boost::system::error_code &ec) { std::cout << "5 s." << std::endl; } void handler2(const boost::system::error_code &ec) { std::cout << "10 s." << std::endl; } int main() { boost::asio::io_service io_service; boost::asio::deadline_timer timer1(io_service, boost::posix_time::seconds(5)); timer1.async_wait(handler1); boost::asio::deadline_timer timer2(io_service, boost:

boost process running() and exit_code() thread safety

ぐ巨炮叔叔 提交于 2020-01-05 08:55:11
问题 I am using boost::process::child and boost::process::async_pipe to start an application and read asynchronously (through the means of boost::asio ) everything that app outputs on screen whenever this happens. I want to check also if the application is alive by using child::running() method; if not running I'd like to read the exit code using child::exit_code . This is very useful ESPECIALLY as it is a way to be notified about an application crashing or exiting unexpectedly (I could not find a

boost::process async IO example doesn't work?

爷,独闯天下 提交于 2020-01-05 06:50:52
问题 The following program: #include <boost/asio.hpp> #include <boost/process.hpp> #include <iostream> namespace bp = boost::process; int main() { boost::asio::io_service ios; std::vector<char> buf(4096); bp::async_pipe ap(ios); bp::child c("/bin/ls", bp::std_out > ap); boost::asio::async_read(ap, boost::asio::buffer(buf), [](const boost::system::error_code &ec, std::size_t size){}); ios.run(); int result = c.exit_code(); std::cout << result << std::endl; } outputs 383 . I would expect it to

boost asio error when read/write more than 100000 messages

此生再无相见时 提交于 2020-01-05 04:44:06
问题 I received the following exception in handleRead() function from boost::asio::read() when I read and write more than 100000 of messages. terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >' what(): asio.ssl error Implementation is below Read Function void start() { boost::asio::async_read(_socket, boost::asio::buffer(_messageHeader, 8), _strand.wrap( boost::bind( handleRead, shared_from

calling async_read again is throwing exception

拥有回忆 提交于 2020-01-05 04:04:23
问题 I have the following code: void GnutellaApp::HandleRead (boost::asio::ip::tcp::socket& socket) { char buf[128]; try { boost::asio::async_read( socket, boost::asio::buffer(buf), boost::asio::transfer_all(), boost::bind(&GnutellaApp::HandleRead, this, boost::ref(socket) ) ); } catch (boost::system::system_error const& e) { std::cout << "Warning: " << e.what() << std::endl; } } When HandleRead is called and async_read is executed, its throwing an exception. In order to asynchronously wait for

Boost - periodic task scheduler

旧街凉风 提交于 2020-01-05 03:43:25
问题 I'm trying to figure out a simple scheduler for periodic tasks. The idea is to provide a mean to schedule periodic execution of std::function<void()> with any given time interval which would be a multiplication of a second. I was trying to write it with the use of boost::asio, but so far I end up with strange behaviour - only one of two scheduled tasks is being repeatedly executed, but it don't follow the interval. Here is the code: #include <functional> #include <iostream> #include <boost

boost::asio::ip::tcp::socket doesn't read anything

ε祈祈猫儿з 提交于 2020-01-04 09:20:21
问题 This is actually my first program in socket programming other than copy-pasting the tutorial code and having fun. Anyway it does not work. I think I have carefully read the documentation but maybe it wasn't enough. I'm suspecting my use of socket::read_some() in read_message() since my problematic program stops at the reading part. I thought the way I used it should be okay because the documentation of socket::read_some() stated that "the function call will block until one or more bytes of

What is the advantage of class member functions to call each other in C++?

笑着哭i 提交于 2020-01-04 05:21:12
问题 I am new to C++. I found that the following programming style is quite interesting to me. I wrote a simplified version here. #include <iostream> using namespace std; class MyClass { public : MyClass(int id_) : id(id_) { cout<<"I am a constructor"<<endl; } bool error = false; void run() { //do something ... if (!error) { read(); } } void read() { //do something ... if (!error) { write(); } } void write() { //do something ... if (!error) { read(); } } private : int id; }; int main() { MyClass