Jak uruchomić „wydarzenie”, gdy mój serwer Boost :: asio tcp zaczyna działać (AKA io_service.run ())?

Opierając się na relacji klient / serwer boost :: asio, muszę uruchomić program klienta z programu serwera tylko wtedy, gdy wątek serwera jest w "czekam na połączenie" stan.

Moje pytanie brzmi: jak mieć wiedzę o tym stanie?

Jako przykład użyjasio przykład / serializacja połączyći zastąp główną funkcję server.cpp tym kodem:

#include <conio.h>
#include <concrt.h> // wait function
#include <future>
#include <thread>

void server_thread( std::promise<bool>& run )
{ 
    boost::asio::io_service io_service;
    s11n_example::server server(io_service, 123);
    // too early to run.set_value( true );
    io_service.run();
    // too late to run.set_value( true );
}

int main(int argc, char* argv[])
{
    std::promise<bool> run;
    std::thread thrd( server_thread, boost::ref( run ) );
    thrd.detach(); 

    bool launched = run.get_future().get();
    // server is waiting for connection
    // launch the client
    if( launched )
    {
        int rc = system( "start client.exe localhost 123" );
        if( rc )
            std::cerr << "system failed returning " << rc << std::endl ;
    }
    else
        std::cerr << "server_thread failure" << std::endl ;

    std::cout << "hit a key to exit"  ;
    while( !_kbhit() )
        Concurrency::wait( 100 );

    return 0;
}

Dzięki,

questionAnswers(1)

yourAnswerToTheQuestion