boost-asio

Is there a way to configure OpenSSL or boost::asio::ssl not to encrypt?

☆樱花仙子☆ 提交于 2019-12-04 06:50:36
For debugging reasons I want sometimes to capture traffic and analyze it. One option to do that was to configure OpenSSL or boost::asio::ssl to keep the transport untouched. I couldn't find anything in the API. If you can configure both ends of your connection you can use a null cipher. When you create your boost::asio::ssl::stream configure it with only ciphers that do not encrypt. This can be done with the OpenSSL API by passing the encapsulated OpenSSL pointer: boost::asio::ssl::stream<boost::asio::ip::tcp::socket> sslSocket(io, ssl); SSL_set_cipher_list(sslSocket.native_handle(), "eNULL");

Non-threaded alternative to waiting on a condition. (Edit: Proactor pattern with boost.asio?)

不羁岁月 提交于 2019-12-04 06:31:35
I am implementing a message passing algorithm. Messages pass between adjacent nodes when they have enough information at the node to compose the message - information that is passed to the node from neighbouring nodes. The implementation is trivial if I make each of messages a thread and use boost::condition to put the thread to sleep until the required information is available. Unfortunately - I have 100k nodes in the graph which would mean 300k threads. When I asked how to make that many threads the answer was that I shouldn't - and re-design instead. My question is: is there a standard

Boost ASIO: How can a server know if a client is still connected?

限于喜欢 提交于 2019-12-04 06:14:42
I am using boost::asio for a server/client application. The server only accepts one connection at a time. I am wondering what is the best way for the server to verify if the client is still connected. The purpose of this is that I would like to be able to know if the client has crashed, so that I can restart listening to new connection attempts. In my application I am using following flags and my read comes out when client disconnects. Please try it if it in your application. Apply this flags just after connection. in my case skt_TCP is of type boost::asio::ip::tcp::socket int32_t accept

How to get the hostname of an ip address by using asio library?

房东的猫 提交于 2019-12-04 06:10:26
问题 I am trying to get hostname from UDP endpoint. However I do not know whether boost.asio supports IP->hostname conversion. Anyone can answer my question? 回答1: getnameinfo is what you want. getnameinfo((sockaddr*)&addr, sizeof(addr), hostname, sizeof(hostname), NULL, NULL, 0); 回答2: #include<asio.hpp> #include<exception> #include<iostream> int main() { try { asio::io_service io_service; asio::ip::udp::resolver rsv(io_service); for(const auto &ele : rsv.resolve(asio::ip::udp::endpoint(asio::ip:

Verify at compile time that objects are created as shared_ptr

谁说我不能喝 提交于 2019-12-04 05:51:08
There are classes that I write (often as part of boost::asio ) whose objects depend on being wrapped in a shared_ptr because they use shared_from_this() . Is there a way to prevent an object from being compiled if it's not instantiated in a shared_ptr ? So, what I'm looking for: std::shared_ptr<MyClass> a = std::make_shared<MyClass>(); // should compile fine std::unique_ptr<MyClass> a = std::make_unique<MyClass>(); // compile error MyClass a; // compile error Make its constructor private and give it a static factory member function that creates a shared_ptr . Don't forget to document your

Better boost asio deadline_timer example

半腔热情 提交于 2019-12-04 05:39:48
I'm after a better example of the boost::asio::deadline_timer The examples given will always time out and call the close method. I tried calling cancel() on a timer but that causes the function passed into async_wait to be called immediately. Whats the correct way working with timers in a async tcp client? You mention that calling cancel() on a timer causes the function passed to async_wait to be called immediately. This is the expected behavior but remember that you can check the error passed to the timer handler to determine if the timer was cancelled. If the timer was cancelled, operation

Boost Asio if condition evaluated differently in static-lib and dll compilations, former resulting in exception in socket io cpp client lib

谁说胖子不能爱 提交于 2019-12-04 05:33:49
问题 Depending on how the socketio c++ library is compiled (static-lib or dll) for the following simple test code, the outcome is either a working executable or one that throws an exception. However, if the instantiation of the io_service is commented out, eg.: // boost::asio::io_service io_service; then the static-lib based version is also working without exception. It seems that there is some interference between the io_service instantiated in main() with the io_service located in the socketIO

boost::asio async condition

怎甘沉沦 提交于 2019-12-04 05:18:45
The idea is to be able to replace multithreaded code with boost::asio and a thread pool, on a consumer/producer problem. Currently, each consumer thread waits on a boost::condition_variable - when a producer adds something to the queue, it calls notify_one / notify_all to notify all the consumers. Now what happens when you (potentially) have 1k+ consumers? Threads won't scale! I decided to use boost::asio , but then I ran into the fact that it doesn't have condition variables. And then async_condition_variable was born: class async_condition_variable { private: boost::asio::io_service& service

C++ Using windows named pipes

寵の児 提交于 2019-12-04 05:14:15
For some reason both the mast and slave fail, however I could find any good examples on how their meant to work, so im not sure where I went wrong. The master never exits the WaitForSingleObject after ConnectNamedPipe, and the slave throws an exception in the first boost::asio::read call, "Waiting for a process to open the other end of the pipe", which I though the WaitNamedPipe was meant to wait for along with the ConnectNamedPipe in the master? master.cpp asio::io_service ioservice; asio::windows::stream_handle in(ioservice); int main() { HANDLE pipe = INVALID_HANDLE_VALUE; try { //create

ASIO ip::tcp::iostream and TCP_NODELAY

烈酒焚心 提交于 2019-12-04 04:53:48
问题 How do i set TCP_NODELAY option if i use ip::tcp::iostream? I need a socket for this, but i can't find how to extract it from iostream. 回答1: use iostream::rdbuf() #include <boost/asio.hpp> int main() { boost::asio::ip::tcp::iostream stream; const boost::asio::ip::tcp::no_delay option( true ); stream.rdbuf()->set_option( option ); } 来源: https://stackoverflow.com/questions/5706641/asio-iptcpiostream-and-tcp-nodelay