boost-asio

What could happen if two threads access the same bool variable at the same time?

隐身守侯 提交于 2020-01-01 11:38:10
问题 I have a cross platform c++ program where I'm using the boost libraries to create an asynchronous timer. I have a global variable: bool receivedInput = false; One thread waits for and processes input string argStr; while (1) { getline(cin, argStr); processArguments(argStr); receivedInput = true; } The other thread runs a timer where a callback gets called every 10 seconds. In that callback, I check to see if I've received a message if (receivedInput) { //set up timer to fire again in 10

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

戏子无情 提交于 2020-01-01 10:08:06
问题 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

boost asio - SSL async_read and async_write from one thread

大憨熊 提交于 2020-01-01 10:06:09
问题 I know that OpenSSL, boost asio SSL implementation is based on, doesn't allow concurrent SSL_read() and SSL_write() (i.e. SSL_read() and SSL_write() executed by different threads). Is it safe to call boost asio async_read() and async_write() on SSL socket from the same thread? Thanks 回答1: The requirement for boost::asio::ssl:::stream is for thread safety; it does not place a requirement as to which thread may initiate operations: Distinct objects: Safe. Shared objects: Unsafe. The application

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

…衆ロ難τιáo~ 提交于 2020-01-01 09:43:10
问题 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. 回答1: 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:

C++ Using windows named pipes

蓝咒 提交于 2020-01-01 09:39:23
问题 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:

How to use Asio (standalone from Boost) in Android NDK?

蓝咒 提交于 2020-01-01 03:46:07
问题 Asio (without Boost) is supposed to be usable with just the headers only right? By default, Asio is a header-only library. (http://think-async.com) I understand that internally Asio still depends on Boost. This is my setup. Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := gatelib LOCAL_SRC_FILES := gatelib.cpp LOCAL_C_INCLUDES += /cygdrive/l/asio-1.5.3/include LOCAL_C_INCLUDES += /cygdrive/l/boost/boost_1_49_0 include $(BUILD_SHARED_LIBRARY) Application.mk APP_STL

Boost Asio type to use for both unix-socket and tcp socket

ぐ巨炮叔叔 提交于 2020-01-01 03:29:08
问题 We have a boost asio based networking code, which connects to a remote side. The local side could be either a tcp4 socket or a unix socket. Is there a typename to use that could hold both of these type of boost sockets? (e.g. something like a base class for both?). Currently our code use boost::asio::generic::stream_protocol::socket for tcp socket, and boost::asio::local::stream_protocol::socket for a unix socket. 回答1: Actually, there's a dedicated ip::tcp::socket type for tcp sockets. As for

C++ boost asio Windows file handle async_read_until infinite loop - no eof

血红的双手。 提交于 2020-01-01 02:17:31
问题 I'm using boost 1.50 with VS2010, reading using a Windows file HANDLE (which seems to be relatively uncommon compared to asio use with sockets). Problem The handle_read callback gets to line 8 and returns the first bit with all of line 1 appended; further callbacks cycle through from line 2 again, ad nauseum: open a short text file (below) get expected handle_read callbacks with correct content for lines 1 through 7 the next callback has a longer-than-expected bytes-read length parameter

Does boost asio io_service guarantee execution of two parallel call chains?

百般思念 提交于 2019-12-31 05:17:08
问题 In my program, using boost asio io_service, I want to have two parallel call chains. Two endless loops writing and reading to two usb ports. But does boost asio io_service guarantee execution of two parallel call chains? Look at this minimal example: #include <boost/asio/io_service.hpp> #include <functional> class Chain { public: Chain(boost::asio::io_service &io_service, const std::string &message) : io_service(io_service) , message(message) {} void call() { std::cout << message << std::endl

iostream and No_delay option

僤鯓⒐⒋嵵緔 提交于 2019-12-31 02:53:05
问题 I am trying to disable the Nagle Algorithm using the answer for the same question: ASIO ip::tcp::iostream and TCP_NODELAY: boost::asio::ip::tcp::iostream socketStream; const boost::asio::ip::tcp::no_delay option( true ); socketStream.rdbuf()->set_option( option ); boost::asio::io_service io_service; tcp::endpoint endpoint (tcp::v4 (), 6666); tcp::acceptor acceptor (io_service, endpoint); std::cout << "Waiting for connection.." << std::endl; acceptor.accept (*socketStream.rdbuf ()); std::cout