boost-asio

Boost Asio single threaded performance

删除回忆录丶 提交于 2019-12-02 18:29:48
I am implementing custom server that needs to maintain very large number (100K or more) of long lived connections. Server simply passes messages between sockets and it doesn't do any serious data processing. Messages are small, but many of them are received/send every second. Reducing latency is one of the goals. I realize that using multiple cores won't improve performance and therefore I decided to run the server in a single thread by calling run_one or poll methods of io_service object. Anyway multi-threaded server would be much harder to implement. What are the possible bottlenecks?

boost:asio::read or boost:asio::async_read with timeout

百般思念 提交于 2019-12-02 18:05:54
问题 Yes. I know there have been a few questions around this time_out in boost::asio . My problem might to too simple for the asio guys to solve here. I am using boost::asio on TCP protocol to read data over a network continuously in a loop as fast as I can. Following function ReadData() gets called continuously from a worker std::thread in a while loop. std::size_t ReadData(std::vector<unsigned char> & buffer, unsigned int size_to_read) { boost::system::error_code error_code; buffer.resize(size

Correct usage of asio::io_service::strand?

情到浓时终转凉″ 提交于 2019-12-02 18:01:46
问题 Here is my code: void client_connection::serve() { asio::async_read(this->socket_, asio::buffer(&buffer_, buffer_.size()), // predicate/condition (do I wrap this?) std::bind(&client_connection::handle_read_predicate, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2), // handler this->strand_.wrap(std::bind(&client_connection::handle_read, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2))); } std::size_t client_connection::handle_read_predicate

non-boost asio checking for errors c++

匆匆过客 提交于 2019-12-02 17:51:07
问题 Is there a way to check for errors in a non-boost asio program using tcp? And is there a way to add an error to the connection randomly? I made a simple Echo Server in C++ for which i now have to generate random errors, but the problem is that i have no clue how. Or if that helps more, i need to check for two dimensional parity (DATA,ACK,NAK). Hope you can help me. Client: #include <iostream> #include <asio\include\asio.hpp> #include <spdlog\spdlog.h> using namespace std; using namespace asio

sending a GET command to an ssl server to get result

人盡茶涼 提交于 2019-12-02 17:47:42
问题 I am trying to send a get request to acounts.google.com to be able to implement a library for C++ OAuth to learn it. I get the following code from this post: Creating a HTTPS request using Boost Asio and OpenSSL and modified it as follow: int main() { try { std::string request = "/o/oauth2/v2/auth"; boost::system::error_code ec; using namespace boost::asio; // what we need io_service svc; ssl::context ctx(svc, ssl::context::method::sslv23_client); ssl::stream<ip::tcp::socket> ssock(svc, ctx);

boost::asio read n bytes from socket to streambuf

流过昼夜 提交于 2019-12-02 17:21:14
I have a serialized structure, which is being sent via socket. I need to read it in chunks, since one of its fields contains the size of the data remaining: I need to read first few bytes, find out the length and read the rest. This is what I have got: boost::asio::streambuf buffer; boost::system::error_code err_code; // here I need to read only first 16 bytes boost::asio::read(socket, buffer, err_code); std::istream is(&buffer); boost::archive::binary_iarchive ia(is); ia >> my_struct; I have taken a look at boost::asio::async_read(s, boost::asio::buffer(data, size), handler); but it can only

Poor boost.ASIO performance

不问归期 提交于 2019-12-02 16:56:43
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 then read a message, and keeps doing this over and over again nonstop. When I run it locally on my own computer I get blazingly fast performance, however; when I run a server on one computer and a client on another computer, even on the same network, the

program crash with boost::asio::spawn and socket::async_receive_from

本小妞迷上赌 提交于 2019-12-02 15:42:48
问题 int main() { boost::asio::io_service io_service; Worker ob1(&io_service); ob1.AsyncRead(); io_service.run(); } void Worker::AsyncRead() { socket.async_receive_from(buffer,endpoint, handler); } void handler (const boost::system::error_code& error, size_t bytes_received) { if(!error) handleData(); AsyncRead(); } Now this works perfectly fine. But if I use boost::Spawn() to do asyncRead() it crashes. void work(boost::asio::io_service* io_service) { auto ob1 = std::make_shared<Worker>(io_service)

Trying to understand Boost.Asio custom service implementation

做~自己de王妃 提交于 2019-12-02 14:18:41
I'm thinking about writing a custom Asio service on top of an existing proprietary 3rd party networking protocol that we are currently using. According to Highscore Asio guide you need to implement three classes to create a custom Asio service: A class derived from boost::asio::basic_io_object representing the new I/O object. A class derived from boost::asio::io_service::service representing a service that is registered with the I/O service and can be accessed from the I/O object. A class not derived from any other class representing the service implementation. The network protocol

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

Deadly 提交于 2019-12-02 13:43:04
问题 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