Exemplo n.º 1
0
bool ConnectionTester::Private::canPing(const QString &host, int *averagePing) const
{
    // TODO: invoke scheduler or tell scheduler something is going on outside of its control
    PingDefinitionPtr pingDef(new PingDefinition(host, 4, 200, 1000, 64, 0, 0, 0, ping::System));
    Ping ping;
    ping.prepare(NULL, pingDef);
    ping.start();
    ping.waitForFinished();

    int resultAvg = ping.averagePingTime();

    if (averagePing)
    {
        *averagePing = resultAvg;
    }

    if (resultAvg > 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    JQNetwork::printVersionInformation();

    Ping ping;
    if ( !ping.begin() ) { return -1; }

    return a.exec();
}
Exemplo n.º 3
0
void bithorde::Keepalive::run()
{
	if (_stale) {
		cerr << "WARNING: " << _client.peerName() << " did not respond to ping. Disconnecting..." << endl;
		return _client.close();
	} else {
		Ping ping;
		ping.set_timeout(MAX_PING_RESPONSE_TIME.total_milliseconds());

		if (_client.sendMessage(Connection::Ping, ping, Message::NEVER, true)) {
			_stale = true;
			_timer.clear();
			_timer.arm(boost::posix_time::seconds(MAX_PING_RESPONSE_TIME.total_seconds() * 1.5));
		} else {
			cerr << "WARNING: " << _client.peerName() << " without input, failed to send prioritized ping. Disconnecting..." << endl;
			return _client.close();
		}
	}
}
Exemplo n.º 4
0
int main() {
  
  list<data_t> liste;
  data_t t ;
  t.x=2;
  
  liste.push_front(t);
  //liste.remove(&t);
  list<data_t>::iterator it = liste.begin();
  liste.erase(it);
  
  assert(liste.size() == 0);
  
  
  
  const int thread_count =6;
  
  
  Acting::Actor::Init();
  
  Ping* ping = new Ping();
  Ping* pong = new Ping();
  
  ping->SetName(string("PING"));
  pong->SetName(string("PONG"));
  
  ping->SetPong(pong);
  pong->SetPong(ping);
  

  /*
    renommer cette methode comme méthode d'instance, ivoquant une méthode 
    static
   */

  /**
     En gros faire en sorte que:
     ping->start();
     pong->start();
   */
  ping->start();
  pong->start();
  
  
  
  //////////////////////////////////////////////////
  Acting::Actor::Finit();
  
  
  return 0;
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);

    if (!QDBusConnection::sessionBus().isConnected()) {
        fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
                "To start it, run:\n"
                "\teval `dbus-launch --auto-syntax`\n");
        return 1;
    }

    Ping ping;
    ping.connect(QDBusConnection::sessionBus().interface(),
                 SIGNAL(serviceOwnerChanged(QString,QString,QString)),
                 SLOT(start(QString,QString,QString)));

    QProcess pong;
    pong.start("./complexpong");

    app.exec();
}
Exemplo n.º 6
0
void DiagnosticsAgent::handle(const QXmppDiagnosticIq &request)
{
    iq.setId(request.id());
    iq.setFrom(request.to());
    iq.setTo(request.from());
    iq.setType(QXmppIq::Result);

    /* software versions */
    QList<Software> softwares;
    Software os;
    os.setType("os");
    os.setName(osName());
    os.setVersion(QSysInfo::productVersion());
    softwares << os;

    Software app;
    app.setType("application");
    app.setName(qApp->applicationName());
    app.setVersion(qApp->applicationVersion());
    softwares << app;
    iq.setSoftwares(softwares);

    /* get DNS servers */
    iq.setNameServers(NetworkInfo::nameServers());

    /* discover interfaces */
    QList<Interface> interfaceResults;
    foreach (const QNetworkInterface &interface, QNetworkInterface::allInterfaces())
    {
        if (!(interface.flags() & QNetworkInterface::IsRunning) ||
            (interface.flags() & QNetworkInterface::IsLoopBack))
            continue;

        Interface result;
#if QT_VERSION >= 0x040500
        result.setName(interface.humanReadableName());
#else
        result.setName(interface.name());
#endif

        // addresses
        result.setAddressEntries(interface.addressEntries());

        // wireless
        WirelessInterface wireless(interface);
        if (wireless.isValid())
        {
            QList<WirelessNetwork> networks = wireless.availableNetworks();
            WirelessNetwork current = wireless.currentNetwork();
            if (current.isValid())
            {
                networks.removeAll(current);
                networks.prepend(current);
            }
            result.setWirelessNetworks(networks);
            result.setWirelessStandards(wireless.supportedStandards());
        }
        interfaceResults << result;
    }
    iq.setInterfaces(interfaceResults);

    /* try to determine gateways */
    QList<QHostAddress> pingAddresses;
    foreach (const QNetworkInterface &interface, QNetworkInterface::allInterfaces())
    {
        if (!(interface.flags() & QNetworkInterface::IsRunning) || (interface.flags() & QNetworkInterface::IsLoopBack))
            continue;

        foreach (const QNetworkAddressEntry &entry, interface.addressEntries())
        {
            if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol && !entry.netmask().isNull() && entry.netmask() != QHostAddress::Broadcast)
            {
                const QHostAddress gateway((entry.ip().toIPv4Address() & entry.netmask().toIPv4Address()) + 1);
                if (!pingAddresses.contains(gateway))
                    pingAddresses.append(gateway);
                break;
            }
        }
    }

    /* run DNS tests */
    foreach (const QString &hostName, m_config.pingHosts)
    {
        QHostAddress address;
        if (resolve(hostName, address)) {
            if (!pingAddresses.contains(address))
                pingAddresses.append(address);
        }
    }

    /* run ping tests */
    QList<Ping> pings;
    foreach (const QHostAddress &address, pingAddresses)
    {
        const Ping ping = NetworkInfo::ping(address, 3);
        pings.append(ping);
        if (address == QHostAddress("8.8.8.8") && ping.sentPackets() != ping.receivedPackets())
            pings.append(NetworkInfo::ping(address, 30));
    }
    iq.setPings(pings);

    /* run traceroute */
    QList<Traceroute> traceroutes;
    foreach (const QString &hostName, m_config.tracerouteHosts)
    {
        QHostAddress address;
        if (resolve(hostName, address)) {
            traceroutes << NetworkInfo::traceroute(address, 3, 4);
        }
    }
    iq.setTraceroutes(traceroutes);

    /* run download */
    if (m_config.transferUrl.isValid()) {
        TransferTester *runner = new TransferTester(this);
        connect(runner, SIGNAL(finished(QList<Transfer>)), this, SLOT(transfersFinished(QList<Transfer>)));
        runner->start(m_config.transferUrl);
    } else {
        emit finished(iq);
    }
}
Exemplo n.º 7
0
Arquivo: main.cpp Projeto: chmike/MPO
int main()
{
    Message::Ptr mm( new Message() );
    MsgA::Ptr ma( new MsgA() );
    MsgB::Ptr mb( new MsgB() );

    MyAction::Ptr action(new MyAction("myAction"));
    std::string op;

    cout << "Test Slot dynamic cast : ";

    op = "   Invoke action m_slotMsgM with mm";
    action->m_slotMsgM( mm );
    action->expectDynamicType( op, "Message" );
    action->expectStaticType( op, "Message" );

    op = "   Invoke action m_slotMsgM with ma";
    action->m_slotMsgM( ma );
    action->expectDynamicType( op, "MsgA" );
    action->expectStaticType( op, "Message" );

    op = "   Invoke action m_slotMsgM with mb";
    action->m_slotMsgM( mb );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "Message" );

    op = "   Invoke action m_slotMsgA with mm";
    action->m_slotMsgA( mm );
    action->expectDynamicType( op, "" );
    action->expectStaticType( op, "" );

    op = "   Invoke action m_slotMsgA with ma";
    action->m_slotMsgA( ma );
    action->expectDynamicType( op, "MsgA" );
    action->expectStaticType( op, "MsgA" );

    op = "   Invoke action m_slotMsgA with mb";
    action->m_slotMsgA( mb );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "MsgA" );

    op = "   Invoke action m_slotMsgB with mm";
    action->m_slotMsgB( mm );
    action->expectDynamicType( op, "" );
    action->expectStaticType( op, "" );

    op = "   Invoke action m_slotMsgB with ma";
    action->m_slotMsgB( ma );
    action->expectDynamicType( op, "" );
    action->expectStaticType( op, "" );

    op = "   Invoke action m_slotMsgB with mb";
    action->m_slotMsgB( mb );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "MsgB" );
    cout << "Ok" << endl;


    cout << "Test Slot static cast  : ";

    op = "   Invoke action m_slotMsgM with mm";
    action->m_slotMsgM.getStaticCastFunction()( mm, nullptr );
    action->expectDynamicType( op, "Message" );
    action->expectStaticType( op, "Message" );

    op = "   Invoke action m_slotMsgM with ma";
    action->m_slotMsgM.getStaticCastFunction()( ma, nullptr );
    action->expectDynamicType( op, "MsgA" );
    action->expectStaticType( op, "Message" );

    op = "   Invoke action m_slotMsgM with mb";
    action->m_slotMsgM.getStaticCastFunction()( mb, nullptr );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "Message" );

    //op = "   Invoke action m_slotMsgA with mm";
    //action->m_slotMsgA( mm ); is not a valid static cast

    op = "   Invoke action m_slotMsgA with ma";
    action->m_slotMsgA.getStaticCastFunction()( ma, nullptr );
    action->expectDynamicType( op, "MsgA" );
    action->expectStaticType( op, "MsgA" );

    op = "   Invoke action m_slotMsgA with mb";
    action->m_slotMsgA.getStaticCastFunction()( mb, nullptr );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "MsgA" );

    //op = "   Invoke action m_slotMsgB with mm";
    //action->m_slotMsgB( mm ); is not a valid static cast

    //op = "   Invoke action m_slotMsgB with ma";
    //action->m_slotMsgB( ma ); is not a valid static cast

    op = "   Invoke action m_slotMsgB with mb";
    action->m_slotMsgB.getStaticCastFunction()( mb, nullptr );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "MsgB" );
    cout << "Ok" << endl;


    // Note: Without links emission has no effect
    cout << "Test Signal type check : ";

    action->m_signalMsgM.emit( mm );
    action->m_signalMsgM.emit( ma );
    action->m_signalMsgM.emit( mb );

    // action->m_signalMsgA.emit( mm ); // Ok: static Error
    action->m_signalMsgA.emit( ma );
    action->m_signalMsgA.emit( mb );

    // action->m_signalMsgB.emit( mm ); // Ok: static Error
    // action->m_signalMsgB.emit( ma ); // Ok: static Error
    action->m_signalMsgB.emit( mb );

    cout << "Ok" << endl;

    cout << "Test connecting links  : ";

    try
    {
        if( Link::isConnected( "myAction::signalMsgM", "myAction::slotMsgM") )
        {
            cout << "Failed!" << endl;
            cout << "   Link myAction::signalMsgM -> myAction::slotMsgM exist." << endl;
            exit(1);
        }

        Link::connect( "myAction::signalMsgM", "myAction::slotMsgM");

        if( !Link::isConnected( "myAction::signalMsgM", "myAction::slotMsgM") )
        {
            cout << "Failed!" << endl;
            cout << "   Link myAction::signalMsgM -> myAction::slotMsgM not created." << endl;
            exit(1);
        }

        if( !Link::disconnect( "myAction::signalMsgM", "myAction::slotMsgM") )
        {
            cout << "Failed!" << endl;
            cout << "   Link myAction::signalMsgM -> myAction::slotMsgM not disconnected." << endl;
            exit(1);
        }

        if( Link::isConnected( "myAction::signalMsgM", "myAction::slotMsgM") )
        {
            cout << "Failed!" << endl;
            cout << "   Link myAction::signalMsgM -> myAction::slotMsgM exist." << endl;
            exit(1);
        }
        cout << "Ok" << endl;


        cout << "Test emit message      : ";

        Link::connect( "myAction::signalMsgM", "myAction::slotMsgM");
        op = "   Invoke action m_signalMsgM with mb";
        action->m_signalMsgM.emit( mb );
        while( Message::processNext() );
        action->expectDynamicType( op, "MsgB" );
        action->expectStaticType( op, "Message" );
        Link::disconnect( "myAction::signalMsgM", "myAction::slotMsgM");
        cout << "Ok" << endl;

        cout << "Test Action network    : ";

        Ping* ping = new Ping("Ping");
        Pong* pong = new Pong("Pong");
        Link::connect( "Ping::output", "Pong::input");
        Link::connect( "Pong::output", "Ping::input");

        if( !Link::isConnected("Ping::output", "Pong::input") )
        {
            cout << "Failed!" << endl;
            cout << "   Link Ping::output -> Pong::input not connected." << endl;
            exit(1);
        }
        if( !Link::isConnected("Pong::output", "Ping::input") )
        {
            cout << "Failed!" << endl;
            cout << "   Link Pong::output -> Ping::input not connected." << endl;
            exit(1);
        }

        Ball::Ptr ball( new Ball() );

        ping->start( ball, 15 );

        while( Message::processNext() );

        if( ball->pingCnt != ball->maxCount )
        {
            cout << "Failed!" << endl;
            cout << "   Ball ping counter is not " <<  ball->maxCount
                 << ". Found " << ball->pingCnt << endl;
            exit(1);
        }

        if( ball->pongCnt != ball->maxCount )
        {
            cout << "Failed!" << endl;
            cout << "   Ball pong counter is not " <<  ball->maxCount
                 <<". Found " << ball->pongCnt << endl;
            exit(1);
        }

        // Add a pong object instance duplicating the message ping transactions
        // Will double the ping pong transactions
        Pong* pong2 = new Pong("Pong2");
        Link::connect( "Ping::output", "Pong2::input");
        Link::connect( "Pong2::output", "Ping::input");

        ping->start( ball, 15 );
        while( Message::processNext() );

        if( ball->pingCnt != ball->maxCount )
        {
            cout << "Failed!" << endl;
            cout << "   Ball ping counter is not " <<  ball->maxCount
                 << ". Found " << ball->pingCnt << endl;
            exit(1);
        }

        if( ball->pongCnt != 2*ball->maxCount )
        {
            cout << "Failed!" << endl;
            cout << "   Ball pong counter is not " <<  2*ball->maxCount
                 <<". Found " << ball->pongCnt << endl;
            exit(1);
        }
        cout << "Ok" << endl;

        cout << "Test free functions    : ";

        SlotFunction<Ball,&catchBall> slotBall;
        Signal<Ball> signalBall;

        if( nbrBallCatched != 0 )
        {
            cout << "Failed!" << endl;
            cout << "   nbrBallCatched counter is not 0"
                 << ". Found " << nbrBallCatched << endl;
            exit(1);
        }

        // Establish a direct connecting between signal and slot
        Link::connect( &signalBall, &slotBall );

        while( Message::processNext() );
        signalBall.emit( ball );
        while( Message::processNext() );

        if( nbrBallCatched != 1 )
        {
            cout << "Failed!" << endl;
            cout << "   nbrBallCatched counter is not 1"
                 << ". Found " << nbrBallCatched << endl;
            exit(1);
        }

        Link::disconnect( &signalBall, &slotBall );

        // Retest using named Signal and slot
        slotBall.setName( "Ball slot" );
        signalBall.setName( "Ball signal" );
        Link::connect( "Ball signal", "Ball slot" );
        while( Message::processNext() );
        signalBall.emit( ball );
        while( Message::processNext() );
        if( nbrBallCatched != 2 )
        {
            cout << "Failed!" << endl;
            cout << "   nbrBallCatched counter is not 2"
                 << ". Found " << nbrBallCatched << endl;
            exit(1);
        }
        cout << "Ok" << endl;


        // destroy all objects
        Action::clearActions();
    }
    catch( std::exception& e )
    {
        cout << "Failed!" << endl;
        cout << "   Exception: " << e.what() << endl;
        exit(1);
    }
    catch( ... )
    {
        cout << "Failed!" << endl;
        cout << "   Unknown exception" << endl;
        exit(1);
    }


    {
        int nbr = 1000000;
        cout << "Timing for " << nbr << " MPO signal ping pong : ";
        cout.flush();
        class Timer {
            double m_start, m_stop;
        public:
            Timer() { start(); stop(); }
            double getTime()
            {
                struct timeval t;
                ::gettimeofday( &t, NULL );
                return double(t.tv_sec) + double(t.tv_usec)/1000000.;
            }

            void start() { m_start = getTime(); }
            void stop() { m_stop = getTime(); }
            double getDelta() { return m_stop - m_start; }
        } timer;

        Ping* ping = new Ping("Ping");
        Pong* pong = new Pong("Pong");
        Link::connect( "Ping::output", "Pong::input");
        Link::connect( "Pong::output", "Ping::input");

        Ball::Ptr ball( new Ball() );
        ping->start( ball, nbr );

        timer.start();
        while( Message::processNext() );
        timer.stop();

        cout << timer.getDelta() << " seconds " << endl;

    }




    return 0;
}
Exemplo n.º 8
0
bool LocalPC::floatIPOnline()
{
    Ping ping;
    return ping.exec(mFloatIP, 3);
}
Exemplo n.º 9
0
bool ChatUser::HandleMessage(SessionPtr session,
                             uint16_t message_type,
                             const void *body,
                             int16_t size) {
  switch (message_type) {
  case MSG_USER_LOGOUT:
  {
    UserLogoutRequest message;
    if (!message.ParseFromArray(body, size)) {
      break;
    }
    return HandleUserLogoutRequest();
  }
  case MSG_CREAT_ROOM:
  {
    CreatRoomRequest message;
    if (!message.ParseFromArray(body, size)) {
      break;
    }
    return HandleCreatRoomRequest(message);
  }
  case MSG_ENTER_ROOM:
  {
    EnterRoomRequest message;
    if (!message.ParseFromArray(body, size)) {
      break;
    }
    return HandleEnterRoomRequest(message);
  }
  case MSG_ROOM_MSG:
  {
    RoomChatRequest message;
    if (!message.ParseFromArray(body, size)) {
      break;
    }
    return HandleRoomChatRequest(message);
  }
  case MSG_LEAVE_ROOM:
  {
    LeaveRoomRequest message;
    if (!message.ParseFromArray(body, size)) {
      break;
    }
    return HandleLeaveRoomRequest(message);
  }
    break;
  case MSG_PING:
  {
    Ping message;
    if (!message.ParseFromArray(body, size)) {
      break;
    }
    return HandlePing(message);
  }
    break;
  case MSG_KEEP_ALIVE:
  {
    KeepAliveRequest message;
    if (!message.ParseFromArray(body, size)) {
      break;
    }
    return HandleKeepAliveRequest(message);
  }
    break;
  default:
    CS_LOG_ERROR("unknown message type");
    break;
  }
  CS_LOG_ERROR("message parse failed");
  return false;
}