コード例 #1
0
void Client::processPong(quint64 elaspedTime)
{
    QtWebsocket::QWsSocket* socket = dynamic_cast<QtWebsocket::QWsSocket*>(sender());
    if(socket && !_needDelete){
        emit pong(socket, elaspedTime);
    }
}
コード例 #2
0
ファイル: mainwindow.cpp プロジェクト: similarJ/qmqtt-client
MainWindow::MainWindow(QMQTT::Client *client, QWidget *parent) :
    QMainWindow(parent),
    _client(client),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->conForm->init(client);
    ui->pubForm->init(client);
    ui->subForm->init(client);

    //add pushBtuoon slots
    connect(ui->pushButtonConnect,SIGNAL(clicked(bool)),this,SLOT(connectServer()));
    connect(ui->pushButtonPusblish,SIGNAL(clicked(bool)),this,SLOT(publishTopic()));
    connect(ui->pushButtonSubscribe,SIGNAL(clicked(bool)),this,SLOT(subscribeTopic()));
    connect(ui->pushButtonQuit,SIGNAL(clicked(bool)),this,SLOT(quitApp()));
    connect(ui->pushButtonClear,SIGNAL(clicked(bool)),this,SLOT(clearMsg()));
    connect(ui->pushButtonAbout,SIGNAL(clicked(bool)),this,SLOT(aboutApp()));

    //connform slots
    connect(_client, SIGNAL(disconnected()), ui->conForm, SLOT(updateUiStatus()));
    connect(_client, SIGNAL(connected()), ui->conForm, SLOT(updateUiStatus()));
    //mainwindow slots
    connect(_client, SIGNAL(connected()), this, SLOT(onMQTT_Connected()));
    connect(_client, SIGNAL(connacked(quint8)), this, SLOT(onMQTT_Connacked(quint8)));
    connect(_client, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onMQTT_error(QAbstractSocket::SocketError)));
    connect(_client, SIGNAL(published(QMQTT::Message &)), this, SLOT(onMQTT_Published(QMQTT::Message &)));
    connect(_client, SIGNAL(pubacked(quint8, quint16)), this, SLOT(onMQTT_Pubacked(quint8, quint16)));
    connect(_client, SIGNAL(received(const QMQTT::Message &)), this, SLOT(onMQTT_Received(const QMQTT::Message &)));
    connect(_client, SIGNAL(subscribed(const QString &)), this, SLOT(onMQTT_subscribed(const QString &)));
    connect(_client, SIGNAL(subacked(quint16, quint8)), this, SLOT(onMQTT_subacked(quint16, quint8)));
    connect(_client, SIGNAL(unsubscribed(const QString &)), this, SLOT(onMQTT_unsubscribed(const QString &)));
    connect(_client, SIGNAL(unsubacked(quint16)), this, SLOT(onMQTT_unsubacked(quint16)));
    connect(_client, SIGNAL(pong()), this, SLOT(onMQTT_Pong()));
    connect(_client, SIGNAL(disconnected()), this, SLOT(onMQTT_disconnected()));
}
コード例 #3
0
ファイル: SocketThread.cpp プロジェクト: Bokkil/MusicHarmony
/**
 * @brief SocketThread::run
 */
void SocketThread::run()
{
    std::cout << tr("connect done in thread : 0x%1").arg(QString::number((intptr_t)QThread::currentThreadId(), 16)).toStdString() << std::endl;

    if( !(conn = mysql_init((MYSQL*)NULL))){
      printf("init fail\n");
      exit(1);
    }

    printf("mysql_init success.\n");

    if(!mysql_real_connect(conn, server, user, password, NULL, 3306, NULL, 0)){
      printf("connect error.\n");
      exit(1);
    }

    printf("mysql_real_connect success.\n");

    if(mysql_select_db(conn, database) != 0){
      mysql_close(conn);
      printf("select_db fail.\n");
      exit(1);
    }

	// Connecting the socket signals here to exec the slots in the new thread
	QObject::connect(socket, SIGNAL(frameReceived(QString)), this, SLOT(processMessage(QString)));
	QObject::connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
	QObject::connect(socket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));
	QObject::connect(this, SIGNAL(finished()), this, SLOT(finished()), Qt::DirectConnection);

	// Launch the event loop to exec the slots
	exec();
}
コード例 #4
0
ファイル: endpoint_impl.hpp プロジェクト: Banaan/websocketpp
void endpoint<connection,config>::pong(connection_hdl hdl, std::string const &
    payload)
{
    lib::error_code ec;
    pong(hdl,payload,ec);
    if (ec) { throw ec; }
}
コード例 #5
0
//MAIN
int main(int argc, char const *argv[])
{
    //SIGUSR1 handler (to avoid interruption)
    struct sigaction sigUsrHandler;
    sigUsrHandler.sa_handler = my_handler_usr_main;
    sigemptyset(&sigUsrHandler.sa_mask);
    sigUsrHandler.sa_flags = 0;
    sigaction(SIGUSR1, &sigUsrHandler, NULL);


    //SIGINT handler configuration
    struct sigaction sigIntHandler;
    sigIntHandler.sa_handler = my_handler_1;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(SIGINT, &sigIntHandler, NULL);

    //Child processes launch
    pid_t pid_ping;
    pid_t pid_pong;

    if ((pid_ping = fork()) == 0)
    {
        ping(getppid());
    }
    else
    {
        pong(pid_ping);
        //Waiting for child processes
        waitpid(pid_pong, NULL, 0);
        waitpid(pid_ping, NULL, 0);
    }

    return 0;
}
コード例 #6
0
TEST(QiAutoService, AutoReConnect)
{
  TestSessionPair pair;

  boost::shared_ptr<Pong> pong(new Pong());
  qi::AnyObject pongAsObject = qi::AnyValue::from(pong).to<qi::AnyObject>();
  qi::Future<unsigned int> fut = pair.server()->registerService("Ping pong", pongAsObject);
  fut.wait();

  qi::AutoService<PongProxy> as("Ping pong", pair.client());
  as.waitForReady().wait();

  EXPECT_EQ(42, as->incr());

  pair.server()->unregisterService(fut.value());
  qi::Future<unsigned int> fut2 = pair.server()->registerService("Ping pong", pongAsObject);
  fut2.wait();

  while(true)
  {
    try
    {
      EXPECT_EQ(43, as->incr().value());
      break;
    }
    catch (std::runtime_error e)
    {
      std::cout << e.what() << std::endl;
    }
  }
}
コード例 #7
0
ファイル: ping_pong_lambda.cpp プロジェクト: alarouche/cppao
	void ping(int remaining)
	{
		active_fn([=]{
			std::cout << "Ping\n";
			if( remaining>0 ) pong(remaining-1);
		});
	}
コード例 #8
0
ファイル: ping.c プロジェクト: RafaelMarinheiro/CS5220-MatMul
int main(int argc, char** argv)
{
    #define MAX_SZ 16384

    int rank, ntrials, pdest;
    static char buf[MAX_SZ];

    MPI_Init(&argc, &argv);

    memset(buf, 0, sizeof(buf));
    pdest   = (argc < 2 ? 1      : atoi(argv[1]));
    ntrials = (argc < 3 ? 100000 : atoi(argv[2]));

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    for (int sz = 1; sz <= MAX_SZ; sz += 1000) {
        if (rank == 0) {
            double t = MPI_Wtime();
            ping(buf, sz, ntrials, pdest);
            t = MPI_Wtime()-t;
            printf("%d %g\n", sz, t/(2*ntrials));
        } else if (rank == pdest) {
            pong(buf, sz, ntrials, 0);
        }
    }

    MPI_Finalize();
    return 0;
}
コード例 #9
0
ファイル: commands.c プロジェクト: AnthonyCalandra/C-IRC-Bawt
void executeCommand(enum Commands command, User *bot, ...)
{
    va_list a_list;
    va_start(a_list, bot);
    char *sender, *cmdStr;
    char **parameters;
    switch (command)
    {
        case PONG:
            pong(bot);
            break;
        case PRIVMSG:
            sender = va_arg(a_list, char *);
            cmdStr = va_arg(a_list, char *);
            parameters = va_arg(a_list, char **);
            if (strcmp("speak", cmdStr) == 0 && strcmp("Anthony`", sender) == 0)
                privmsg(bot, sender, parameters[0]);
            else if (strcmp("rolldice", cmdStr) == 0)
                rolldice(bot, sender, atoi(parameters[0]));
            else if (strcmp("die", cmdStr) == 0 && strcmp("Anthony`", sender) == 0)
                killBot(bot);
            else if (strcmp("coolmeter", cmdStr) == 0)
                coolmeter(bot, sender, parameters[0]);
            else if (strcmp("fight", cmdStr) == 0)
                fight(bot, sender, parameters[0], parameters[1]);
            else if (strcmp("getlatestpost", cmdStr) == 0)
                getLatestRlPost(bot, sender);
            break;
    }

    va_end(a_list);
}
コード例 #10
0
void Client::addSocket(QtWebsocket::QWsSocket *socket)
{
    sockets << socket;

    connect(socket, SIGNAL(frameReceived(QString)), this, SLOT(processMessage(QString)));
    connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
    connect(socket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));
}
コード例 #11
0
ファイル: interpret.c プロジェクト: hunggarrebel/KbpsIRC
void
interpret(s_line line)
{
	if (!strcmp(line.command, "PING"))
		pong(line.params[0]);

	flushline(line);
}
コード例 #12
0
ファイル: irc.cpp プロジェクト: Harak/irc-mind
void irc::run()
{
  if ((_buf = _sock->recv()) == "")
    return;
  if (Utils::getToken(_buf, " ", 1) == "PING")
    pong();
  checkActions();
}
コード例 #13
0
ファイル: test-http.cpp プロジェクト: bsletten/monarch
static void runHttpPongTest(TestRunner& tr)
{
   tr.test("Http Pong");

   // create kernel
   Kernel k;

   // set thread stack size in engine (128k)
   k.getEngine()->getThreadPool()->setThreadStackSize(131072);

   // optional for testing --
   // limit threads to 2: one for accepting, 1 for handling
   //k.getEngine()->getThreadPool()->setPoolSize(2);
   k.getEngine()->getThreadPool()->setPoolSize(10);

   // start engine
   k.getEngine()->start();

   // create server
   Server server;
   InternetAddress address("0.0.0.0", 19100);

   // create SSL/generic http connection servicer
   HttpConnectionServicer hcs;
//   SslContext context;
//   SslSocketDataPresenter presenter1(&context);
//   NullSocketDataPresenter presenter2;
//   SocketDataPresenterList list(false);
//   list.add(&presenter1);
//   list.add(&presenter2);
   server.addConnectionService(&address, &hcs);//, &list);

   // create test http request servicer
   PongHttpRequestServicer pong("/");
   hcs.addRequestServicer(&pong, false);

   if(server.start(&k))
   {
      printf("\nServer started on %s, CTRL+C to quit\n",
         address.toString(false).c_str());
   }
   else if(Exception::get() != NULL)
   {
      printf("\nServer start failed with errors=%s\n",
         Exception::get()->getMessage());
   }

   // wait indefinitely
   Thread::sleep(0);

   server.stop();
   printf("Server stopped.\n");

   // stop kernel engine
   k.getEngine()->stop();

   tr.passIfNoException();
}
コード例 #14
0
ファイル: DISPPONG.C プロジェクト: daveoman/DCRabbit_10
void main ()
{
	brdInit();
	displayInit();

	drawBox(BOXTOPLEFTX, BOXTOPLEFTY,
			  BOXWIDTH-BOXTOPLEFTX, BOXHEIGHT-BOXTOPLEFTY);
	pong();
}
コード例 #15
0
void WebSocketServer::processNewConnection()
{
    QtWebsocket::QWsSocket* clientSocket = server->nextPendingConnection();
    QObject::connect(clientSocket, SIGNAL(frameReceived(QString)), this, SLOT(processMessage(QString)));
    QObject::connect(clientSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
    QObject::connect(clientSocket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));
    clients << clientSocket;
    std::cout << tr("Client connected").toStdString() << std::endl;
}
コード例 #16
0
ファイル: xboardengine.cpp プロジェクト: eliaskousk/cutechess
void XboardEngine::finishGame()
{
	if (!m_ftPing && state() == FinishingGame)
	{
		// Give the engine enough time to send all pending
		// output relating to the current game
		m_gotResult = true;
		QTimer::singleShot(200, this, SLOT(pong()));
	}
}
コード例 #17
0
ファイル: qmqtt_client.cpp プロジェクト: ehntoo/qmqtt
//---------------------------------------------
//---------------------------------------------
void Client::onReceived(Frame &frame)
{
    quint8 qos = 0;
    bool retain, dup;
    QString topic;
    quint16 mid = 0;
    quint8 header = frame.header();
    quint8 type = GETTYPE(header);
    Message message;
    qCDebug(client, "handleFrame: type=%d", type);

    switch(type) {
    case CONNACK:
        //skip reserved
        frame.readChar();
        handleConnack(frame.readChar());
        break;
    case PUBLISH:
        qos = GETQOS(header);;
        retain = GETRETAIN(header);
        dup = GETDUP(header);
        topic = frame.readString();
        if( qos > MQTT_QOS0) {
            mid = frame.readInt();
        }
        message.setId(mid);
        message.setTopic(topic);
        message.setPayload(frame.data());
        message.setQos(qos);
        message.setRetain(retain);
        message.setDup(dup);
        handlePublish(message);
        break;
    case PUBACK:
    case PUBREC:
    case PUBREL:
    case PUBCOMP:
        mid = frame.readInt();
        handlePuback(type, mid);
        break;
    case SUBACK:
        mid = frame.readInt();
        qos = frame.readChar();
        emit subacked(mid, qos);
        break;
    case UNSUBACK:
        emit unsubacked(mid);
        break;
    case PINGRESP:
        emit pong();
        break;
    default:
        break;
    }
}
コード例 #18
0
ファイル: Player.cpp プロジェクト: BenchMine/BenchMine
//The `DataPacket` get deleted in the Session:receivePacket() method
void Player::handleDataPacket(RakLib::DataPacket* packet) {
	uint8 packetID = (*packet)[0];

	this->_server->getLogger()->debug("Packet ID: %02X", packetID);

	switch (packetID) {
	case MinecraftPackets::PING:
	{
		Ping ping(packet);
		ping.decode();


		Pong pong(ping.pingID);
		pong.encode();
		this->addToQueue(&pong, RakLib::Session::QueuePriority::IMMEDIATE);
	}
	break;

	case MinecraftPackets::CLIENT_CONNECT:
	{
		ClientConnect clientConnect(packet);
		clientConnect.decode();

		ServerHandshake serverHandshake(this->_ip, this->_port, clientConnect.sendPing, clientConnect.sendPing * 1000L);
		serverHandshake.encode();
		this->addToQueue(&serverHandshake, RakLib::Session::QueuePriority::IMMEDIATE);
	}
	break;

	case MinecraftPackets::LOGIN_PACKET:
	{
		Login login(packet);
		login.decode();

		if (login.protocol != NETWORK_PROTOCOL || login.protocol2 != NETWORK_PROTOCOL){
			if (login.protocol < NETWORK_PROTOCOL || login.protocol2 < NETWORK_PROTOCOL){
				//this->addToQueue(new LoginStatus(1)); // Client outdated
				//close("Wrong Protocol: Client is outdated.");
			}
			if (login.protocol > NETWORK_PROTOCOL || login.protocol2 > NETWORK_PROTOCOL){
				//addPacketToQueue(new LoginStatus(2)); // Server outdated
				//close("Wrong Protocol: Server is outdated.");
			}
		}

		this->_server->getLogger()->debug("%s (%s:%d) have joined...", login.username.c_str(), this->_ip.c_str(), this->_port);

		
	}
	break;

	}
}
コード例 #19
0
ファイル: UdpHandler.cpp プロジェクト: Koukan/rtype
int         UdpHandler::ping(Net::Packet &, uint64_t time_recv)
{
	Net::Packet     pong(18);
	pong << static_cast<uint64_t>(time_recv);
	pong << static_cast<uint8_t>(UDP::PONG);
	NetworkModule::get().sendPacketUDP(pong);
	Net::Packet     pong2(18);
	pong2 << static_cast<uint64_t>(Net::Clock::getMsSinceEpoch());
	pong2 << static_cast<uint8_t>(UDP::PING);
	NetworkModule::get().sendPacketUDP(pong2);
	return 1;
}
コード例 #20
0
ファイル: server_dispatch.c プロジェクト: vdloo/daust
char *run_command(char *cmd)
{
	char *r	= NULL;
	if (cmd) {
		if (check_if_stop(cmd)) 	kill_daemon();
		if (check_if_ping(cmd)) 	r = pong();
		if (check_if_list(cmd)) 	r = list();
		if (check_if_block(cmd)) 	r = block();
		if (check_if_trace(cmd))	r = trace();
	}
	return r;
}
コード例 #21
0
ファイル: Server.cpp プロジェクト: me21/QtWebsocket
void Server::processNewConnection()
{
	QtWebsocket::QWsSocket* clientSocket = server->nextPendingConnection();

	QObject::connect(clientSocket, SIGNAL(frameReceived(QString)), this, SLOT(processMessage(QString)));
	QObject::connect(clientSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
	QObject::connect(clientSocket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));

	clients << clientSocket;

	qDebug() << tr("Client connected (%1)").arg(clientSocket->isEncrypted() ? "encrypted" : "not encrypted");
}
コード例 #22
0
ファイル: client.cpp プロジェクト: hef/strup
void client::onPing(client& c, std::string message)
{
    std::smatch match;
    std::regex e("PING :(.*)");
    std::regex_match(message, match, e);

    if(match.size())
    {
        std::string pong("PONG :");
        pong += match[1];
        c.send(pong);
    }
}
コード例 #23
0
ファイル: NodeMessages.cpp プロジェクト: Artanomell/schat
/*!
 * Чтение нового входящего сообщения.
 */
bool NodeMessages::read(PacketReader *reader)
{
  if (ChatId(reader->sender()).type() != ChatId::UserId)
    return cleanup();

  m_sender = Ch::channel(reader->sender(), ChatId::UserId);
  if (!m_sender)
    return cleanup();

  MessageNotice packet(m_type, reader);
  m_packet          = &packet;
  const qint64 date = m_packet->date();

  FeedEvent *event = createEvent();
  if (event->status != Notice::OK) {
    reject(event->status);
    FeedEvents::start(event);
    return cleanup();
  }

  if (packet.direction() == Notice::Internal) {
    if (m_packet->command() == LS("ping"))
      pong(date);

    Core::i()->route(m_dest);
    delete event;
    return cleanup();
  }

  FeedPtr feed  = m_dest->feed(FEED_NAME_MESSAGES, true, false);
  event->diffTo = event->date;
  event->date   = m_packet->date();

  if (m_dest->type() == ChatId::UserId && m_dest->status().value() == Status::Offline) {
    event->status = Notice::ChannelOffline;
    reject(event->status);

    NodeMessagesDB::add(packet, event->status);
    Ch::gc(m_dest);
  }
  else {
    if (feed->get(MESSAGES_FEED_LOGGING_KEY).status == Notice::OK)
      NodeMessagesDB::add(packet);

    Core::i()->route(m_dest);
  }

  FeedStorage::save(feed, m_packet->date());
  FeedEvents::start(event);
  return cleanup();
}
コード例 #24
0
ファイル: dsme-wdd.c プロジェクト: faenil/dsme
static void mainloop(unsigned sleep_interval,
                     int      pipe_to_child,
                     int      pipe_from_child)
{
    int child_ping_count = 0;

    // NOTE: One should NOT do anything potentially blocking in the mainloop.
    //       Otherwise we run the risk of being late to kick the HW watchdogs.
    while (run) {
        // kick WD's right before sleep
        dsme_wd_kick();

        // sleep precisely
        struct timespec remaining_sleep_time = { sleep_interval, 0 };
        while (nanosleep(&remaining_sleep_time, &remaining_sleep_time) == -1 &&
               errno == EINTR)
        {
            // interrupt could mean that someone wants to force a WD kick;
            // also, we have to kick just before stopping running
            dsme_wd_kick();
            if (!run) {
                goto done_running;
            }

            // interrupt may have come from the dsme server; consider it alive
            child_ping_count = 0;
        }

        // kick WD's right after sleep
        dsme_wd_kick();

        // make sure the dsme server (the child) is alive
        if (pong(pipe_from_child)) {
            child_ping_count = 0;
        } else if (child_ping_count >= DSME_MAXPING) {
            // dsme server has failed to respond in due time
            fprintf(stderr, ME "dsme-server nonresponsive; quitting\n");
            run = false;
            dsme_abnormal_exit = true;
            goto done_running;
        }

        // ping the dsme server
        ping(pipe_to_child);
        ++child_ping_count;
    }

done_running:
    return;
}
コード例 #25
0
TEST(QiAutoService, SimpleUsage)
{
  TestSessionPair pair;

  boost::shared_ptr<Pong> pong(new Pong());
  qi::AnyObject pongAsObject = qi::AnyValue::from(pong).to<qi::AnyObject>();
  qi::Future<unsigned int> fut = pair.server()->registerService("Ping pong", pongAsObject);
  fut.wait();

  qi::AutoService<PongProxy> as("Ping pong", pair.client());
  as.waitForReady().wait();

  EXPECT_EQ(42, as->incr().value());
}
コード例 #26
0
void trollRegister()
{
  boost::shared_ptr<Pong> pong(new Pong());
  qi::AnyObject pongAsObject = qi::AnyValue::from(pong).to<qi::AnyObject>();
  unsigned int j = trash->server()->registerService("Ping pong", pongAsObject).value();

  qi::os::msleep(200);
  for (int i = 0; i < 200; i++)
  {
    trash->server()->unregisterService(j).value();
    qi::os::msleep(qi::os::ustime() % 50);
    j = trash->server()->registerService("Ping pong", pongAsObject).value();
    qi::os::msleep(qi::os::ustime() % 50);
  }
}
コード例 #27
0
void SocketThread::run()
{
    std::cout << tr("connect done in thread : 0x%1")
        .arg(QString::number((unsigned int)QThread::currentThreadId(), 16))
        .toStdString() << std::endl;

    // Connecting the socket signals here to exec the slots in the new thread
    QObject::connect(socket, SIGNAL(frameReceived(QString)), this, SLOT(processMessage(QString)));
    QObject::connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
    QObject::connect(socket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));
    QObject::connect(this, SIGNAL(finished()), this, SLOT(finished()), Qt::DirectConnection);

    // Launch the event loop to exec the slots
    exec();
}
コード例 #28
0
ファイル: netmanager.cpp プロジェクト: garinh/planeshift
bool NetManager::HandleUnknownClient (LPSOCKADDR_IN addr, MsgEntry* me)
{
    psMessageBytes* msg = me->bytes;

    // The first msg from client must be "firstmsg", "alt_first_msg" or "PING"
    if (msg->type!=client_firstmsg && msg->type!=npcclient_firstmsg && msg->type!=MSGTYPE_PING)
        return false;

    if ( msg->type == MSGTYPE_PING )
    {
        psPingMsg ping(me);

        if (!(ping.flags & PINGFLAG_REQUESTFLAGS) && !psserver->IsReady())
            return false;

        int flags = 0;
        if (psserver->IsReady()) flags |= PINGFLAG_READY;
        if (psserver->HasBeenReady()) flags |= PINGFLAG_HASBEENREADY;
        if (psserver->IsFull(clients.Count(),NULL)) flags |= PINGFLAG_SERVERFULL;

        // Create the reply to the ping
        psPingMsg pong(0,ping.id,flags);
        pong.msg->msgid = GetRandomID();

        csRef<psNetPacketEntry> pkt;
        pkt.AttachNew(new
                      psNetPacketEntry(pong.msg->priority, 0,
                                       0, 0, (uint32_t) pong.msg->bytes->GetTotalSize(),
                                       (uint16_t) pong.msg->bytes->GetTotalSize(), pong.msg->bytes));

        SendFinalPacket(pkt,addr);
        return false;
    }

    // Don't accept any new clients when not ready, npcclients is accepted
    if(msg->type==client_firstmsg && !psserver->IsReady())
        return false;

    // Create and add the client object to client list
    Client* client = clients.Add(addr);
    if (!client)
        return false;

    // This is for the accept message that will be sent back
    me->clientnum = client->GetClientNum();

    return true;
}
コード例 #29
0
TEST(QiAutoService, Signals)
{
  int n = 0;
  TestSessionPair pair;

  boost::shared_ptr<Pong> pong(new Pong());
  qi::AnyObject pongAsObject = qi::AnyValue::from(pong).to<qi::AnyObject>();
  qi::Future<unsigned int> fut = pair.server()->registerService("Ping pong", pongAsObject);
  fut.wait();

  qi::AutoService<PongProxy> as("Ping pong", pair.client());
  as.serviceRemoved.connect(boost::bind<void>(&setTo42, &n));
  pair.server()->unregisterService(fut.value()).wait();

  qi::os::msleep(100);
  EXPECT_EQ(42, n);
}
コード例 #30
0
TEST(QiAutoService, IsReadyMethod)
{
  int n = 0;
  TestSessionPair pair;

  boost::shared_ptr<Pong> pong(new Pong());
  qi::AnyObject pongAsObject = qi::AnyValue::from(pong).to<qi::AnyObject>();
  qi::Future<unsigned int> fut = pair.server()->registerService("Ping pong", pongAsObject);
  fut.wait();

  qi::AutoService<PongProxy> as("Ping pong", pair.client());
  qi::Future<void> fut2 = as.waitForReady();

  fut2.connect(&setTo42, &n);
  fut2.wait();
  qi::os::msleep(100);

  EXPECT_EQ(42, n);
}