boost-asio

LNK2019 when including asio headers, solution generated with cmake

痞子三分冷 提交于 2019-12-03 03:01:20
I am trying to port a big project from gcc (Linux) to msvc (windows), using cmake and boost libraries. The project compile and runs fine for gcc but on msvc it returns the following error: Dyna.obj : error LNK2019: unresolved external symbol "void __cdecl boost::throw_exception(class std::exception const &)" (?throw_exception@boost@@YAXABVexception@std@@@Z) referenced in function "void __cdecl boost::asio::detail::do_throw_error(class boost::system::error_code const &,char const *)" (?do_throw_error@detail@asio@boost@@YAXABVerror_code@system@3@PBD@Z) I tried running a simple project using

Boost Asio pattern with GUI and worker thread

大憨熊 提交于 2019-12-03 00:41:31
I would like to implement a Boost Asio pattern using a thread for GUI and a worker thread for some socket IO. The worker thread will use boost::asio::io_service to manage a socket client. All operations on sockets will be performed by the worker thread only. The GUI thread needs to send and receive messages from the worker thread. I can't exactly figure how to implement this pattern using Boost Asio. I've already implemented the socket communication in the standard Asio way (I call io_service.run() from the worker thread and I use async_read_some / async_send ). I don't need strands because io

boost:asio thread pool implementation for occasionally synchronized tasks

断了今生、忘了曾经 提交于 2019-12-02 23:45:41
I have a "main" function that performs many small, independent tasks each once per time step. However, after each time step, I must wait for all of the tasks to complete before stepping forward. I want to make the program multithreaded. I have tried implementations with the boost-offshoot threadpool, and I've tried using a vector of (shared pointers to) threads, and I've tried the asio threadpool ideas (using an io_service, establishing some work, then distributing run to the threads and posting handlers to the io_service). All of these seem to have a lot of overhead creating and destroying

Making SSL Connection using Boost Asio

↘锁芯ラ 提交于 2019-12-02 23:39:08
问题 Basically a have the code to make an http call to server and handle the response but I want to secure the data travelling and make the call https. For that I have this executor.hpp class Executor { public : Executor(Cli &cli):ssock(svc) { //! Get a list of endpoints corresponding to the server name. boost::asio::ip::tcp::resolver resolver(svc); boost::asio::ip::tcp::resolver::query query(cli.getIP(), "8080"); endpoint_iterator = resolver.resolve(query); } int connect(); int write

TCP keep_alive does not work if you switch off wifi to cause an abrupt connection loss

荒凉一梦 提交于 2019-12-02 20:03:02
问题 Scenario: I have a client and server written using boost::asio 1.63. I am using keep_alive feature in tcp sockets to detect connection losses. Following is the keep_alive code setup. boost::asio::io_service ioService; boost::asio::ip::tcp::socket mySocket(ioService); #ifdef __APPLE__ unsigned int timeoutMillis = 2000; struct timeval tvs; tvs.tv_sec = timeoutMillis / 1000; tvs.tv_usec = (timeoutMillis % 1000) * 1000; if (setsockopt(mySocket.native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tvs,

boost::asio::spawn yield as callback

霸气de小男生 提交于 2019-12-02 19:29:42
I'm trying to rewrite a project using boost::asio::spawn coroutines. Some parts of the project cannot be changed. For example, the storage protocol library is also written with boost::asio , but without coroutines. The problem is how to convert yield_context into a normal callback (a boost::function object or a classical functor). This is what we have in the storage library API: void async_request_data(uint64_t item_id, boost::function< void(Request_result *) > callback); As we know from examples, the asio yield context can be used like this: my_socket.async_read_some(boost::asio::buffer(data)

Asynchronous Mysql connector

梦想的初衷 提交于 2019-12-02 19:10:00
Do any asynchronous connectors exist for Mysql that can be used within a C or C++ application? I'm looking for something that can be plugged into a reactor pattern written in Boost.Asio . [Edit:] Running a synchronous connector in threads is not an option. http://forums.mysql.com/read.php?45,183339,183339 enjoy Updated link to the original article showing how to do async mysql queries: http://jan.kneschke.de/projects/mysql/async-mysql-queries-with-c-api/ I had a similar problem with a very different technologies: Twisted python (reactor-based IO) and sqlAlchemy (??). While searching for a

Starting another program via system() call blocks the socket

一世执手 提交于 2019-12-02 19:07:08
问题 I searched google and StackOverflow for anything similar to this but the closest ones were C code and the situation wasn't the same... I have a program which starts another one via cstdlib's system() call to a script and everything works fine, the problem is when I have to test new code, so I stop execution (Crtl+C and kill -9 pid produce the same error), compile the new executable and try to run it again, that's when I get the message that the socket is already in use. My program uses an

Using the same istream with a resizeable streambuf in boost::asio

Deadly 提交于 2019-12-02 18:34:46
问题 I am reading data off a socket using boost asio async_read(). I have the following members of the reader class which persist through the lifetime of the program: boost::asio::streambuf recv_data; std::istream stream_is(&recv_data); The async_read call looks like this: boost::asio::async_read(ep_ptr->get_sock(), recv_data, boost::asio::transfer_exactly(n), boost::bind(&IProtocol::handle_data_recv, &protocol, boost::asio::placeholders::error)); My question is, what would happen if I am reading

boost::asio cleanly disconnecting

你。 提交于 2019-12-02 18:33:57
Sometimes boost::asio seems to disconnect before I want it to, i.e. before the server properly handles the disconnect. I'm not sure how this is possible because the client seems to think its fully sent the message, yet when the server emits the error its not even read the message header... During testing this only happens maybe 1 in 5 times, the server receives the client shut down message, and disconnects the client cleanly. The error: "An existing connection was forcibly closed by the remote host" The client disconnecting: void disconnect() { boost::system::error_code error; //just creates a