boost-asio

boost async_wait and adding “this” in a bind [duplicate]

假装没事ソ 提交于 2019-12-08 07:47:08
问题 This question already has an answer here : How to use boost bind with a member function (1 answer) Closed 4 years ago . In this example of using a boost asynchronous timer inside a class, the author added "this" pointer to the bind function inside m_timer.async_wait method. That's strange because the handler is a public method (message(void)) that takes no argument, so why the hell using boost::bind and especially the pointer "this" ? class handler { public: handler(boost::asio::io_service&

Error in websocketpp library and boost in windows Visual Studio 2015 [closed]

邮差的信 提交于 2019-12-08 07:44:51
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm trying to compile this simple example https://github.com/zaphoyd/websocketpp/blob/master/examples/echo_server/echo_server.cpp from the developer github, but I'm getting strange errors outside the code. I have also tried turning on the /Za option as shown in this post: VC++ 2012 and Boost incompatibility -

C++ boost::asio::async_write send problems

牧云@^-^@ 提交于 2019-12-08 07:33:34
问题 When I call async_write() , the remote peer is not receiving data until I call async_write() again. For example, I have 3 packets, a , b , and c : SendPacket(a); // the remote side receives nothing SendPacket(b); // the remote side receives packet a SendPacket(c); // the remote side receives packet b This is my code for sending: void Session::SendPacket(packet p) { dword len = p.Lenght(); byte* buffer_send = new byte[len + 4]; //4 cause of the header memcpy(buffer_send + 4, p.GetRaw(), len);

How to use libpqxx to receive notifications from the PostgreSQL database?

南笙酒味 提交于 2019-12-08 07:32:45
问题 I'm writing C++ applicatoin which needs to receive notifications for data changes from PostgreSQL through libpqxx library. But it's tutorial doesn't include such use case. The notifications must be received on multiple channels. Also I'm using boost::asio as networking library and for me is preferable if possible to use asio socket classes with asynchronous callbacks for notification events instead of polling of raw BSD style sockets. Can someone provide sample code for this or links to some

async_resolve and async_connect params lifetime

杀马特。学长 韩版系。学妹 提交于 2019-12-08 06:14:00
问题 I would like to know what is lifetime of objects passed to mentioned methods. async_resolve ip::basic_resolver::async_resolve(const query & q, ResolveHandler handler); (1) Do I need to keep resolver alive until handler is called? (yes) (2) Does async_resolve copy query object? (I am passing one created on the stack - yes) { boost::asio::ip::tcp::resolver::query query(host_, port_); resolver_.async_resolve(query, ); } (3) Is boost::asio::ip::tcp::resolver::iterator returned in handler by value

Boost::Asio with Main/Workers threads - Can I start event loop before posting work?

▼魔方 西西 提交于 2019-12-08 05:59:15
问题 I'm new to Boost::Asio. I want to have a "Manager" process a lock free queue on a worker thread and send the result back to the main thread. Borrowing heavily from the answer here (Boost Asio pattern with GUI and worker thread) I've been able to get close to what I want. Here is the code: #include "stdafx.h" #include <boost/asio.hpp> #include <boost/lockfree/spsc_queue.hpp> #include <boost/signals2.hpp> #include "Task.h" class Manager { typedef boost::signals2::signal<void(int)> Signal;

Boost.Asio SSL context load_verify_paths not loading certificate(s)

只谈情不闲聊 提交于 2019-12-08 05:28:27
I have code to retrieve all root certificates in the Windows certificate store for the current user: #include <windows.h> #include <Wincrypt.h> inline std::vector<std::string> system_root_certificates() { std::vector<std::string> certs; HCERTSTORE hStore; PCCERT_CONTEXT pCertContext = NULL; if (!(hStore = ::CertOpenStore( CERT_STORE_PROV_SYSTEM_A, 0, NULL, CERT_SYSTEM_STORE_CURRENT_USER, "Root"))) return certs; do { if (pCertContext = ::CertFindCertificateInStore( hStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_ANY, NULL, pCertContext)) { certs.push_back("-----BEGIN CERTIFICATE--

Boost.Asio iostream flush not working?

六月ゝ 毕业季﹏ 提交于 2019-12-08 04:20:14
问题 any ideas why stream.flush(); won't work? boost::asio::ip::tcp::iostream stream("localhost","5000"); assert(stream.good()); stream << 1; stream.flush(); while(true); it's only flushed if the loop is removed and the line boost::this_thread::sleep(boost::posix_time::seconds(1)); is executed (much later). Thanks Update: I did some more debugging and the problem is in fact not the flush command. If I let my code connect to a netcat server everything works fine. I assume the problem is that both

boost::asio::async_read bind compilation error

浪子不回头ぞ 提交于 2019-12-08 03:52:28
问题 I can't figure out why I get this error : /usr/local/include/boost/asio/impl/read.hpp: In member function ‘void boost::asio::detail::read_op<AsyncReadStream, boost::asio::mutable_buffers_1, CompletionCondition, ReadHandler>::operator()(const boost::system::error_code&, size_t, int) [with AsyncReadStream = boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, CompletionCondition = boost::asio::detail::transfer_at_least_t, ReadHandler

boost coroutine server crashes when writting data to client

旧城冷巷雨未停 提交于 2019-12-08 03:33:06
问题 I made my server based on boost coroutine echo server example, simply receives and writes back some data. It crashes when writing data to client, and more strangely, it only crashes when using mutiple cores. Here's the server, it reads 4 bytes and write back "OK", within 1 second as timeout: #include <winsock2.h> #include <windows.h> #include <iostream> using namespace std; #include <boost/thread/thread.hpp> #include <boost/asio.hpp> #include <boost/asio/spawn.hpp> using namespace boost;