boost-asio

Alternative to missing method in last version of Boost asio library

假装没事ソ 提交于 2019-12-02 07:27:09
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(); } The application worked fine with boost_1_63_0. But when I try update to boost_1_70_0, the compiler (MS

Using boost::asio::io_service as class member field

青春壹個敷衍的年華 提交于 2019-12-02 07:03:16
问题 I have class where I use boost asio library: Header: class TestIOService { public: void makeConnection(); static TestIOService getInst(); private: TestIOService(std::string address); std::string address; // boost::asio::io_service service; }; Impl: #include <boost/asio/ip/address.hpp> #include <boost/asio/ip/udp.hpp> #include "TestIOService.h" void TestIOService::makeConnection() { boost::asio::io_service service; boost::asio::ip::udp::socket socket(service); boost::asio::ip::udp::endpoint

simultaneous read and write to child's stdio using boost.process

不想你离开。 提交于 2019-12-02 06:58:17
i am trying to write and read to child's stdio using boost.process using something like this: boost::asio::io_service writeService, readService; bp::async_pipe in{writeService}; bp::async_pipe out{readService}; bp::child process(CompressCmd.c_str(), bp::std_in < in, bp::std_out > out); Buffer src; src.reserve(4 * 1024 * 1024); integer_type read = 0; //std::atomic_int64_t totalWrite{0}; integer_type totalWrite = 0; while (callback(CallbackActions::NeedMoreInput, src, read)) { in.async_write_some( boost::asio::buffer(src.data(), read), [](const boost::system::error_code &e, std::size_t) { }); //

Random EOF in boost asio in multi thread

我与影子孤独终老i 提交于 2019-12-02 06:52:24
问题 I am quite new to boost asio and I am experiencing random End of File in a multi threaded server. I could reproduce my problem in this small example: Server: This is a simple echo server. The protocol is straightforward : (1) A client Connect (2) The server reads one byte. This byte is the length of the string to read and send back. (3) The server reads N bytes. (4) The server send back N+1 bytes to the client and goes back to (2). When the Client disconnect An EOF is captured in (3) and the

Non blocking boost io_service for deadline_timers

a 夏天 提交于 2019-12-02 05:31:34
问题 After reading the documentation for boost::asio::deadline_timer, it seems io_service::run() and the handler method are called on the same thread. Is there any method to create a timer on one thread while running the io_service object on the background thread? 回答1: For fun and glory here's how to combine a thread queue with asio deadline timer to dispatch non-blocking tasks from a deadline timer: Live On Coliru #ifndef HEADER_GUARD_CUSTOM_THREADPOOL_HPP #define HEADER_GUARD_CUSTOM_THREADPOOL

Binding boost asio to local tcp endpoint

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 05:28:26
问题 I'm trying to bind a boost asio tcp socket to a local network interface specifically. When is the correct time to call the bind() method on the socket? _endpoint points to the remote ip/port, e.g. 192.168.0.15:8888. // Invoke async. connect. Immediate return, no throw. _socket.async_connect(_endpoint, boost::bind(&MyTransceiver::handleConnect, this, boost::asio::placeholders::error)); Within MyTransceiver::handleConenct() , I tried the following code: boost::asio::ip::tcp::endpoint local_end

Read child process stdout in a separate thread with BOOST process

落花浮王杯 提交于 2019-12-02 04:55:32
I have a main program that uses boost process library to spawn a child process that prints Hello World ! on its stdout every 5 seconds. I would like to read/monitor the stdout of the child process in the main process when it becomes available along with performing other operations within the main program. I have tried out the examples for boost asynchronous IO ( http://www.boost.org/doc/libs/1_66_0/doc/html/boost_process/tutorial.html ) but all these seem to block the main program until the child process has exited. Do we need to read the childs stdout in a separate thread ? Can someone please

Passing around boost::asio::ip::tcp::socket

社会主义新天地 提交于 2019-12-02 04:18:56
问题 Alright, this is my current code snippet: namespace bai = boost::asio::ip; bai::tcp::socket tcp_connect(std::string hostname, std::string port) { try { boost::asio::io_service io_service; bai::tcp::resolver resolver(io_service); // we now try to get a list of endpoints to the server bai::tcp::resolver::query query(hostname, port); bai::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); bai::tcp::resolver::iterator end; // looking for a successful endpoint connection bai::tcp

ASIO getting a tcp endpoint directly from an asynchronous resolve

本秂侑毒 提交于 2019-12-02 03:57:10
I'm looking to use the ASIO standalone library (not Boost ASIO), I am trying to set up a client to connect to a server on a specific port. I saw in the porthopper example that it is possible to get the endpoint without having to deal with an iterator. asio::io_service io_service; // Determine the location of the server. tcp::resolver resolver(io_service); tcp::resolver::query query(host_name, port); tcp::endpoint remote_endpoint = *resolver.resolve(query); I am trying to do the resolve of the query using resolver async_resolve() member function. This is the code I currently have: asio::io

Implementing an event timer using boost::asio

Deadly 提交于 2019-12-02 03:23:36
The sample code looks long, but actually it's not so complicated :-) What I'm trying to do is, when a user calls EventTimer.Start(), it will execute the callback handler (which is passed into the ctor) every interval milliseconds for repeatCount times. You just need to look at the function EventTimer::Stop() #include <iostream> #include <string> #include <boost/asio.hpp> #include <boost/bind.hpp> #include <boost/thread.hpp> #include <boost/function.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <ctime> #include <sys/timeb.h> #include <Windows.h> std::string