boost-asio

C++ Boost.ASIO: passing accepted TCP connection from one opened socket to another using Windows APIs ( while works with Linux APIs)?

倾然丶 夕夏残阳落幕 提交于 2019-12-01 00:47:43
I was trying to learn how to re assign accepted connection using Boost.ASIO and Windows API's. found this code sample added to it includes and use of namespaces so now it is compilable - just copy and paste and here you go... "The parameter is incorrect" exception at the same place code poster had it=( So here is code: #include <iostream> #include <boost/asio.hpp> #ifdef _WIN32 #include "Windows.h" #endif using namespace boost::asio::ip; using namespace std; int main(){ int m_nPort = 12345; boost::asio::io_service io_service; tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), m_nPort)

boost::thread data structure sizes on the ridiculous side?

感情迁移 提交于 2019-12-01 00:45:16
Compiler: clang++ x86-64 on linux. It has been a while since I have written any intricate low level system code, and I ussualy program against the system primitives (windows and pthreads/posix). So, the in#s and out's have slipped from my memory. I am working with boost::asio and boost::thread at the moment. In order to emulate synchronous RPC against an asynchronous function executor ( boost::io_service with multiple threads io::service::run 'ing where requests are io_serviced::post 'ed), I am using boost synchronization primitives. For curiosities sake I decided to sizeof the primitives.

boost asio buffer lazy allocation

廉价感情. 提交于 2019-12-01 00:18:13
Async operations. Now I pass preallocated byte buffer, for example: s.async_receive_from( boost::asio::buffer( preallocated_pointer, preallocated_size ), _remote_endpoint, boost::bind(...) ); Is it possible to make lazy allocation for this and other calls? Tanner Sansbury Lazy allocation, or allocating when the resource is needed , can be accomplished using boost::asio::null_buffers . null_buffers can be used to obtain reactor-style operations within Boost.Asio. This can be useful for integrating with third party libraries, using shared memory pools, etc. The Boost.Asio documentation provides

Select functionality in boost::asio

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 23:34:03
问题 I am going to use boost::asio lib for my project. But it's not quite obvious which function is corresponding to select() from native socket C lib. Is that available in asio? Or does boost provide an alternative to find out if a socket is ready? 回答1: The high-level design of Boost.Asio is based on the Proactor desing pattern. Thus, you don't need to poll on select . Instead, submit your completion handler for an asynchronous operation, and when the operation gets completed - the completion

Calculating the sum of a large vector in parallel

◇◆丶佛笑我妖孽 提交于 2019-11-30 23:22:35
Problem background I have a program that currently takes way too long to sum up large std::vector s of ~100 million elements using std::accumulate , and this is a bottleneck. I want it to be faster and I want it to be an asynchronous calculation so the GUI/Server doesn't block. The calculation should also be using multithreading so I can reduce the time it takes to sum up a vector. I want to split up the summation so that each thread sums a part of the vector and then when all partial sums are calculated, each thread's partial sum should be added together to get the total summation. Boost.Asio

How to discard data as it is sent with boost::asio?

那年仲夏 提交于 2019-11-30 22:34:03
I'm writing some code that reads and writes to serial device using boost::asio class. However, when sending several strings between programs, I've noticed that on the receiving program the data is read in the order as it was written to the serial port, and not as the data is sent from the other program - If I start reading data some seconds later, I don't get the values that I am sending at the moment but those that were sent previously. I'm assuming this is caused by how I am setting up my boost::asio::serial_port : int main(int argc, char const *argv[]){ int baud=atoi(argv[1]); std::string

cancel a deadline_timer, callback triggered anyway

橙三吉。 提交于 2019-11-30 22:09:42
I was suprised not to find a clock component in boost::asio (our any widely used library) so it tried making a simple, minimalistic, implementation for testing some of my code. Using boost::asio::deadline_timer I made the following class class Clock { public: using callback_t = std::function<void(int, Clock&)>; using duration_t = boost::posix_time::time_duration; public: Clock(boost::asio::io_service& io, callback_t callback = nullptr, duration_t duration = boost::posix_time::seconds(1), bool enable = true) : m_timer(io) , m_duration(duration) , m_callback(callback) , m_enabled(false) , m

Can I use a stackful coroutine as the wait handler of a steady_timer which is defined inside the very stackful coroutine?

寵の児 提交于 2019-11-30 20:53:11
Can I use stackful coroutine and boost::asio::steady_timer::async_wait in the following way? The point is that (my understanding, not sure) during waiting, local variable timer is not on the stack and thus inaccessible. So can the callback proceed normally? (FYI, it works fine on my Mac using clang++5.0 .) boost::asio::io_service io; void Work(boost::asio::yield_context yield) { boost::asio::steady_timer timer(io); timer.expires_from_now(std::chrono::seconds(5)); timer.async_wait(yield); cout << "Woke up." << endl; } int main() { boost::asio::spawn(io, Work); io.run(); return 0; } I think it

How to decipher a boost asio ssl error code?

我怕爱的太早我们不能终老 提交于 2019-11-30 20:09:47
I've got an occasional communications failure in a boost asio ssl implementation, the super helpful error message returned by boost is 'asio.ssl:336458004' I suspect that the numerical figure is some sort of aggregate construct composed of SSL flags, I say that because the linux error codes, the boost asio error codes and the ssl error codes do not have any reference to '336458004', so presumably it must be constructed dynamically. Can anyone provide some insight into how I should decipher this error code?, Thanks. they use ERR_PACK from crypto/err/err.h this will allow converting error to

library not found for -lboost_system

本小妞迷上赌 提交于 2019-11-30 19:21:11
I installed boost using macports. The files appear to be in /opt/local/include/boost/ My makefile is no longer working and I get the following error Undefined symbols: "boost::system::generic_category()", referenced from: __static_initialization_and_destruction_0(int, int)in client.o __static_initialization_and_destruction_0(int, int)in client.o "boost::system::system_category()", referenced from: boost::asio::error::get_system_category() in client.o boost::system::error_code::error_code()in client.o __static_initialization_and_destruction_0(int, int)in client.o ld: symbol(s) not found