当前位置: 首页>>代码示例>>C++>>正文


C++ TimeStamp::getUSec方法代码示例

本文整理汇总了C++中TimeStamp::getUSec方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeStamp::getUSec方法的具体用法?C++ TimeStamp::getUSec怎么用?C++ TimeStamp::getUSec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeStamp的用法示例。


在下文中一共展示了TimeStamp::getUSec方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
  TimeStamp start;
  TimeStamp newTime;
  TimeStamp dt;
  start.now();
  while (1) {
    newTime.now();
    dt=newTime-start;
    std::cout << dt.getSec() << "sec " << dt.getUSec() << "usec\n";
    if (dt.getSec()>3) return 0;
  }
  return 1;
}
开发者ID:BackupTheBerlios,项目名称:dope,代码行数:14,代码来源:test-timestamp.cpp

示例2: listener

int 
Server::main()
{
#ifndef WINDOOF
  signal(SIGPIPE,sigPipeHandler);
#endif
  signal(SIGTERM,sigTermHandler);
  signal(SIGINT,sigTermHandler);

  NetStreamBufServer listener(m_config.m_port);
  listener.init();
  listener.newConnection.connect(SigC::slot(*this,&Server::handleNewConnection));
  listener.dataAvailable.connect(SigC::slot(*this,&Server::handleDataAvailable));
  listener.connectionClosed.connect(SigC::slot(*this,&Server::handleConnectionClosed));

  if (!m_config.m_useMetaServer)
    m_config.m_metaServer.clear();
  else{
    if (m_config.m_myAddress.empty())
      /* myAddress not set => we only report our port and the metaserver will use the ip
	 from which it was connected (if the server is behind a nat-firewall this means
	 that the nat firewall must redirect this port to the server) */
      m_maddr.port=m_config.m_port;
    else{
      /* myAddress is set => we report it to the metaserver (if the address contains a :
	 the port is assumed to follow the :
      */
      m_maddr.adr=m_config.m_myAddress;
      std::string::size_type pos(m_maddr.adr.find_first_of(':'));
      if (pos!=std::string::npos) {
	if (pos+1<m_maddr.adr.size())
	  stringToAny(std::string(m_maddr.adr,pos+1),m_maddr.port);
	else
	  m_maddr.port=m_config.m_port;
	m_maddr.adr=std::string(m_maddr.adr,0,pos);
      }
    }
  }
  const std::string &msURI(m_config.m_metaServer);
  if (!msURI.empty()) {
    try {
      MetaServer metaServer(msURI.c_str());
      RegisterServer reg;
      reg.host=m_maddr;
      ServerRegistered answer;
      metaServer.rpc(reg,answer);
      std::cerr << "Metaserver answered !:\nRegistered: " << answer.registered << " , secret:"<<answer.secret<<std::endl;
      m_msecret=answer.secret;

      updateMetaserver();
    }catch(...){
      DOPE_WARN("Could not connect to Metaserver\n");
    }
  }
  
  TimeStamp start;
  start.now();
  TimeStamp oldTime;
  TimeStamp newTime;
  TimeStamp stepSize(0,11111); // ~90Hz
  TimeStamp frameSize(stepSize);
  TimeStamp dt;
  TimeStamp null;
  TimeStamp timeOut;
  oldTime.now();
  unsigned frames=0;
  while (!quit) {
    listener.select(&null); // test for input and emit corresponding signals
    newTime.now();
    dt=newTime-oldTime;
    // consume remaining time (this is the end of one frame)
    while(dt<frameSize) {
      timeOut=(frameSize-dt);
      listener.select(&timeOut);
      newTime.now();
      dt=newTime-oldTime;
    }

#ifdef ADIC_DEBUG_TIMING
    // todo remove again
    // last frame size was dt
    // and it should have been frameSize
    std::cerr << "\nLast frame took: "
	      << (R(dt.getSec())+(R(dt.getUSec())/1000000))
	      << " and should have taken: "
	      << (R(frameSize.getSec())+(R(frameSize.getUSec())/1000000));
#endif

    frameSize=(dt-frameSize);
    int eframes=1;
    while (frameSize>stepSize) {
      ++eframes;
      frameSize-=stepSize;
    }
    frameSize=stepSize-frameSize;

#ifdef ADIC_DEBUG_TIMING
    // todo remove again
    std::cerr << "\nFramesize: "<< (R(frameSize.getSec())+(R(frameSize.getUSec())/1000000));
    if (eframes>1) {
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:adic,代码行数:101,代码来源:server.cpp


注:本文中的TimeStamp::getUSec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。