¿Cómo lanzar un "evento" cuando mi servidor Boost :: asio tcp simplemente comienza a ejecutarse (AKA io_service.run ())?

Basado en una relación boost :: asio cliente / servidor, tengo que iniciar el programa cliente desde el programa del servidor solo cuando el hilo del servidor está en un "esperando para estar conectado" estado.

Mi pregunta es ¿cómo tener el conocimiento de ese estado?

Como muestra use elasio ejemplo / serialización enlazary reemplace la función principal de server.cpp con ese código:

#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;
}

Gracias,

Respuestas a la pregunta(1)

Su respuesta a la pregunta