boost-asio

boost::asio async server design

一个人想着一个人 提交于 2019-11-27 10:58:55
问题 Currently I'm using design when server reads first 4 bytes of stream then read N bytes after header decoding. But I found that time between first async_read and second read is 3-4 ms. I just printed in console timestamp from callbacks for measuring. I sent 10 bytes of data in total. Why it takes so much time to read? I running it in debug mode but I think that 1 connection for debug is not so much to have a 3 ms delay between reads from socket. Maybe I need another approach to cut TCP stream

How to get IP address of boost::asio::ip::tcp::socket?

风格不统一 提交于 2019-11-27 10:25:33
问题 I'm writing a server in C++ using Boost ASIO library. I'd like to get the string representation of client IP to be shown in my server's logs. Does anyone know how to do it? 回答1: The socket has a function that will retrieve the remote endpoint. I'd give this (long-ish) chain of commands a go, they should retrieve the string representation of the remote end IP address: asio::ip::tcp::socket socket(io_service); // Do all your accepting and other stuff here. asio::ip::tcp::endpoint remote_ep =

Using ZeroMQ together with Boost::ASIO

落花浮王杯 提交于 2019-11-27 10:20:58
问题 I've got a C++ application that is using ZeroMQ for some messaging. But it also has to provide a SGCI connection for an AJAX / Comet based web service. For this I need a normal TCP socket. I could do that by normal Posix sockets, but to stay cross platform portable and make my life easier (I hope...) I was thinking of using Boost::ASIO. But now I have the clash of ZMQ wanting to use it's own zmq_poll() and ASIO it's io_service.run() ... Is there a way to get ASIO to work together with the 0MQ

using multiple io_service objects

与世无争的帅哥 提交于 2019-11-27 09:53:57
问题 I have my application in which listen and process messages from both internet sockets and unix domain sockets. Now I need to add SSL to the internet sockets, I was using a single io_service object for all the sockets in the application. It seems now I need to add separate io_service objects for network sockets and unix domain sockets. I don't have any threads in my application and I use async_send and async_recieve and async_accept to process data and connections. Please point me to any

c++ work queues with blocking

好久不见. 提交于 2019-11-27 09:38:09
This question should be a little simpler than my last few. I've implemented the following work queue in my program: Pool.h: // tpool class // It's always closed. :glasses: #ifndef __POOL_H #define __POOL_H class tpool { public: tpool( std::size_t tpool_size ); ~tpool(); template< typename Task > void run_task( Task task ){ boost::unique_lock< boost::mutex > lock( mutex_ ); if( 0 < available_ ) { --available_; io_service_.post( boost::bind( &tpool::wrap_task, this, boost::function< void() > ( task ) ) ); } } private: boost::asio::io_service io_service_; boost::asio::io_service::work work_;

boost::asio + std::future - Access violation after closing socket

笑着哭i 提交于 2019-11-27 09:37:47
I am writing a simple tcp client to send and receive single lines of text. The asynchronous operations are handled by std::future in order to faciliate blocking queries with timeouts. Unfortunately, my test application crashes with an access violation when destructing the server object. Here is my code: TCPClient.hpp #ifndef __TCPCLIENT_H__ #define __TCPCLIENT_H__ #include <boost/asio.hpp> #include <boost/asio/use_future.hpp> #include <memory> #include <vector> #include <future> #include <thread> #include <chrono> #include <iostream> #include <iterator> using namespace boost::asio; class

BOOST ASIO - How to write console server

不羁的心 提交于 2019-11-27 09:10:54
I have to write asynchronous TCP Sever. TCP Server have to be managed by console (for eg: remove client, show list of all connected client, etcc..) The problem is: How can I attach (or write) console, which can calls above functionalities. This console have to be a client? Should I run this console client as a sepearate thread? I have read a lot of tutorials and I couldn`t find a solution to my problem. ServerTCP code class ServerTCP { public: ServerTCP(boost::asio::io_service& A_ioService, unsigned short A_uPortNumber = 13) : m_tcpAcceptor(A_ioService, tcp::endpoint(tcp::v4(), A_uPortNumber))

Boost linker error: Unresolved external symbol “class boost::system::error_category const & __cdecl boost::system::get_system_category(void)”

岁酱吖の 提交于 2019-11-27 08:50:04
I'm just getting started with Boost for the first time, details: I'm using Visual Studio 2008 SP1 I'm doing an x64 Build I'm using boost::asio only (and any dependencies it has) My code now compiles, and I pointed my project at the boost libraries (after having built x64 libs) and got past simple issues, now I am facing a linker error: 2>BaseWebServer.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_system_category(void)" (?get_system_category@system@boost@@YAAEBVerror_category@12@XZ) 2>BaseWebServer.obj : error LNK2001:

Should the exception thrown by boost::asio::io_service::run() be caught?

江枫思渺然 提交于 2019-11-27 08:37:58
问题 boost::asio::io_service::run() throws a boost::system::system_error exception in case of error. Should I handle this exception? If so, how? my main.cpp code is something like this: main() { boost::asio::io_service queue; boost::asio::io_service::work work(queue); { // set some handlers... **queue.run();** } // join some workers... return 0; } 回答1: Yes. It is documented that exceptions thrown from completion handlers are propagated. So you need to handle them as appropriate for your

boost::asio::async_read ends without fulfilling the completion condition

守給你的承諾、 提交于 2019-11-27 08:27:09
问题 On Windows, I am observing that if an async_read operation successfully completes on a serial port, and I immediately initiate another async_read operation to read n bytes, the second async_read operation immediately completes unexpectedly with success and 0 bytes transferred. after the second async_read operation, if a third async_read operation is initiated to read n bytes, then it will complete with success and n bytes transferred // where buffer_size(buffer) and n are both greater than 1