• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ chrono::milliseconds类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中std::chrono::milliseconds的典型用法代码示例。如果您正苦于以下问题:C++ milliseconds类的具体用法?C++ milliseconds怎么用?C++ milliseconds使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: nonblock_recv

	size_t Socket::nonblock_recv(std::vector<std::string::value_type> &buf, const std::chrono::milliseconds &timeWait) const
	{
		size_t recv_len = ~0;
	#ifdef WIN32
        WSAPOLLFD event = {
            socket_handle,
            POLLRDNORM,
            0
        };

        if (1 == ::WSAPoll(&event, 1, timeWait.count() ) && event.revents & POLLRDNORM)
        {
			recv_len = ::recv(socket_handle, buf.data(), buf.size(), 0);
		}
	#elif POSIX
        struct ::pollfd event = {
            socket_handle,
            POLLIN,
            0
        };

        if (1 == ::poll(&event, 1, timeWait.count() ) && event.revents & POLLIN)
		{
			recv_len = ::recv(socket_handle, buf.data(), buf.size(), MSG_NOSIGNAL);
		}
	#else
		#error "Undefine platform"
	#endif
		return recv_len;
	}
开发者ID:HelloZCB,项目名称:httpserver,代码行数:30,代码来源:Socket.cpp


示例2: nonblock_recv

	long Socket::nonblock_recv(std::vector<std::string::value_type> &buf, const std::chrono::milliseconds &timeout) const
	{
		long recv_len = ~0;
	#ifdef WIN32
        WSAPOLLFD event = {
			this->socket_handle,
            POLLRDNORM,
            0
        };

		if (1 == ::WSAPoll(&event, 1, static_cast<::INT>(timeout.count() ) ) && event.revents & POLLRDNORM)
        {
			recv_len = ::recv(this->socket_handle, buf.data(), static_cast<int>(buf.size() ), 0);
		}
	#elif POSIX
        struct ::pollfd event = {
			this->socket_handle,
            POLLIN,
            0
        };

		if (1 == ::poll(&event, 1, timeout.count() ) && event.revents & POLLIN)
		{
			recv_len = ::recv(this->socket_handle, buf.data(), buf.size(), 0);
		}
	#else
		#error "Undefine platform"
	#endif
		return recv_len;
	}
开发者ID:RaySrc,项目名称:httpserver,代码行数:30,代码来源:Socket.cpp


示例3: nonblock_send

	size_t Socket::nonblock_send(const std::vector<std::string::value_type> &buf, const size_t length, const std::chrono::milliseconds &timeWait) const
	{
		size_t send_len = ~0;
	#ifdef WIN32
        WSAPOLLFD event = {
            socket_handle,
            POLLWRNORM,
            0
        };

        if (1 == ::WSAPoll(&event, 1, timeWait.count() ) && event.revents & POLLWRNORM)
		{
			send_len = ::send(socket_handle, buf.data(), length, 0);
		}
	#elif POSIX
        struct ::pollfd event = {
            socket_handle,
            POLLOUT,
            0
        };

        if (1 == ::poll(&event, 1, timeWait.count() ) && event.revents & POLLOUT)
		{
			send_len = ::send(socket_handle, buf.data(), length, MSG_NOSIGNAL);
		}
	#else
		#error "Undefine platform"
	#endif
		return send_len;
	}
开发者ID:HelloZCB,项目名称:httpserver,代码行数:30,代码来源:Socket.cpp


示例4: if

bool
Piped_request_waiter::Wait(std::chrono::milliseconds timeout)
{
    fd_set rfds;
    FD_ZERO(&rfds);
    FD_SET(read_pipe, &rfds);

    timeval tv = {0, 0};
    timeval* tvp = &tv;
    if (timeout.count() > 0) {
        /* Calculate full seconds and remainder in microseconds. */
        std::chrono::seconds full_sec =
                std::chrono::duration_cast<std::chrono::seconds>(timeout);
        tv.tv_sec = full_sec.count();
        timeout -= full_sec;
        tv.tv_usec = std::chrono::microseconds(timeout).count();
    } else if (timeout.count() < 0) {
        tvp = nullptr;
    }

    int rc = select(read_pipe + 1, &rfds, nullptr, nullptr, tvp);

    if (rc == 0) {
        /* Timeout occurred. */
        return false;
    } else if (rc < 0) {
        VSM_SYS_EXCEPTION("Wait pipe wait error");
    }

    Ack();

    return true;
}
开发者ID:ugcs,项目名称:vsm-cpp-sdk,代码行数:33,代码来源:piped_request_waiter.cpp


示例5: nonblock_accept

	Socket Socket::nonblock_accept(const std::chrono::milliseconds &timeWait) const
	{
		System::native_socket_type client_socket = ~0;
	#ifdef WIN32
        WSAPOLLFD event = {
            socket_handle,
            POLLRDNORM,
            0
        };

        if (1 == ::WSAPoll(&event, 1, timeWait.count() ) && event.revents & POLLRDNORM)
		{
			client_socket = ::accept(socket_handle, static_cast<sockaddr *>(nullptr), static_cast<int *>(nullptr) );
		}
	#elif POSIX
        struct ::pollfd event = {
            socket_handle,
            POLLIN,
            0
        };

        if (1 == ::poll(&event, 1, timeWait.count() ) && event.revents & POLLIN)
		{
			client_socket = ::accept(socket_handle, static_cast<sockaddr *>(nullptr), static_cast<socklen_t *>(nullptr) );
		}
	#else
		#error "Undefine platform"
	#endif
		return Socket(client_socket);
	}
开发者ID:HelloZCB,项目名称:httpserver,代码行数:30,代码来源:Socket.cpp


示例6: main

int main(int argc, char* argv[])
{
	std::string receivingInterfaceFilter;

	if(argc>1) {
		if(std::string(argv[1])=="-h") {
			std::cout << "Listens on incoming announces for a specific time. Returns a compact format about all received announcements." << std::endl;
			std::cout << "syntax: " << argv[0] << " <interface name>" << std::endl;
			std::cout << "return format: <family type> <uuid> <type> <name> <address> <netmask> <http port> <interface address> <interface netmask>" << std::endl;
			return 0;
		} else {
			receivingInterfaceFilter = argv[1];
		}
	}

	static const std::chrono::milliseconds timeToWait(10000);
	hbm::devscan::Receiver receiver;

	std::cerr << "Collecting announcements for " << timeToWait.count() << "msec" << std::endl;
	// after collecting announcements for a defined time, we set the announcement callback. As a result, the announce callback is being called for all current announcements.
	try {
		receiver.start_for(timeToWait);
	} catch(hbm::exception::exception& e) {
		std::cerr << "Error starting the receiver: " << e.what() << std::endl;
		return 1;
	}

	receiver.setAnnounceCb(std::bind(&announceCb, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, receivingInterfaceFilter));
	return 0;
}
开发者ID:mloy,项目名称:devscan,代码行数:30,代码来源:scanclientcompact.cpp


示例7: setReceiveTimeout

void Connection::setReceiveTimeout(std::chrono::milliseconds timeout) {
  timeval tv;
  tv.tv_sec = timeout.count() / 1000;
  tv.tv_usec = (timeout.count() % 1000) * 1000;

  if (-1 == setsockopt(socket_, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))) {
    close();
    throw std::runtime_error("Setting receive timeout on socket failed.");
  }
}
开发者ID:zjzcn,项目名称:CoaPP,代码行数:10,代码来源:Connection.cpp


示例8: setResetTimer

void ProxyDestinationMap::setResetTimer(std::chrono::milliseconds interval) {
  assert(interval.count() > 0);
  inactivityTimeout_ = static_cast<uint32_t>(interval.count());
  resetTimer_ =
      folly::AsyncTimeout::make(proxy_->eventBase(), [this]() noexcept {
        resetAllInactive();
        scheduleTimer(false /* initialAttempt */);
      });
  scheduleTimer(true /* initialAttempt */);
}
开发者ID:facebook,项目名称:mcrouter,代码行数:10,代码来源:ProxyDestinationMap.cpp


示例9: foo

void foo() {
   std::chrono::milliseconds const timeout(400);
    
   for (int i = 1; i <= 10; ++i) {      
      std::this_thread::sleep_for(timeout);
       
      std::lock_guard<std::mutex> const guard(mutex);
   	  std::cout << i << timeout.count() << " ms" << std::endl;
   }   
}
开发者ID:CCJY,项目名称:coliru,代码行数:10,代码来源:main.cpp


示例10: wait_for

bool socket::wait_for(const std::chrono::milliseconds& timeout) const
{
    auto fds = net::fd_set{};
    FD_ZERO(&fds);
    FD_SET(m_fd, &fds);
    net::timeval tv{
        static_cast<decltype(tv.tv_sec)>(timeout.count() / 1000),
        static_cast<decltype(tv.tv_usec)>(timeout.count() % 1000 * 1000)
    };
    const auto result = net::select(m_fd+1, &fds, nullptr, nullptr, &tv);
    return result > 0;
}
开发者ID:ruoka,项目名称:db4cpp,代码行数:12,代码来源:socket.cpp


示例11: setSampleTime

void PIDController::setSampleTime(const std::chrono::milliseconds newSampleTime)
{
    if (newSampleTime.count() <= 0) {
        return;
    }

    auto ratio = (float)newSampleTime.count() / mSampleTime.count();

    mKi *= ratio;
    mKd /= ratio;
    mSampleTime = newSampleTime;
}
开发者ID:Babody,项目名称:STM_HAL,代码行数:12,代码来源:PIDController.cpp


示例12: formatFPS

std::string StringUtils::formatFPS(std::chrono::milliseconds delta, unsigned int precision)
{
	std::string formatStr;
	long long deltaValue = delta.count();
	if (deltaValue != 0.0)
		formatStr.append(std::to_string(1000.0 / delta.count()));
	else
		formatStr.append("0.0");
	if (formatStr.size() > precision)
		formatStr = formatStr.substr(0, precision);
	return formatStr;
}
开发者ID:albertowd,项目名称:StringUtils,代码行数:12,代码来源:StringUtils.cpp


示例13: VLOG

void
ConnectionManager::initiateGracefulShutdown(
  std::chrono::milliseconds idleGrace) {
  if (idleGrace.count() > 0) {
    idleLoopCallback_.scheduleTimeout(idleGrace);
    VLOG(3) << "Scheduling idle grace period of " << idleGrace.count() << "ms";
  } else {
    action_ = ShutdownAction::DRAIN2;
    VLOG(3) << "proceeding directly to closing idle connections";
  }
  drainAllConnections();
}
开发者ID:Kbrunham,项目名称:folly,代码行数:12,代码来源:ConnectionManager.cpp


示例14: updateY

void Player::updateY(const std::chrono::milliseconds elapsed_time,
                     const Map& map,
                     ParticleTools& particle_tools)
{
    // Update velocity
    const units::Acceleration gravity = is_jump_active_ && velocity_.y < 0
        ? kJumpGravity
        : kGravity;
    velocity_.y = std::min(velocity_.y + gravity * elapsed_time.count(),
                kMaxSpeedY);
    // Calculate delta
    const units::Game delta = velocity_.y * elapsed_time.count();
    if (delta > 0.0) {
        // Check collision in the direction of delta
        CollisionInfo info = getWallCollisionInfo(map, bottomCollision(delta));
        // React to collision
        if (info.collided) {
            pos_.y = units::tileToGame(info.row) - kCollisionYBottom;
            velocity_.y = 0.0;
            is_on_ground_ = true;
        } else {
            pos_.y += delta;
            is_on_ground_ = false;
        }
        // Check collision in the direction opposite to delta
        info = getWallCollisionInfo(map, topCollision(0));
        if (info.collided) {
            pos_.y = units::tileToGame(info.row) + kCollisionYHeight;
            createHeadBumpParticle(particle_tools);
        }
    } else {
        // Check collision in the direction of delta
        CollisionInfo info = getWallCollisionInfo(map, topCollision(delta));
        // React to collision
        if (info.collided) {
            pos_.y = units::tileToGame(info.row) + kCollisionYHeight;
            createHeadBumpParticle(particle_tools);
            velocity_.y = 0.0;
        } else {
            pos_.y += delta;
            is_on_ground_ = false;
        }
        // Check collision in the direction opposite to delta
        info = getWallCollisionInfo(map, bottomCollision(0));
        if (info.collided) {
            pos_.y = units::tileToGame(info.row) - kCollisionYBottom;
            is_on_ground_ = true;
        }
    }
}
开发者ID:LuXiaohong,项目名称:cavestory-sdl2,代码行数:50,代码来源:player.cpp


示例15: nonblock_send_all

	long SocketAdapterTls::nonblock_send_all(const void *buf, const size_t length, const std::chrono::milliseconds &timeout) const
	{
		size_t record_size = ::gnutls_record_get_max_size(this->session);

		if (0 == record_size)
		{
			return -1;
		}

		size_t total = 0;

		while (total < length)
		{
			::gnutls_record_set_timeout(this->session, static_cast<unsigned int>(timeout.count() ) );

			if (record_size > length - total)
			{
				record_size = length - total;
			}

			const long send_size = ::gnutls_record_send(this->session, reinterpret_cast<const uint8_t *>(buf) + total, record_size);

			if (send_size < 0)
			{
				return send_size;
			}

			total += send_size;
		}

		return static_cast<long>(total);
	}
开发者ID:RaySrc,项目名称:httpserver,代码行数:32,代码来源:SocketAdapterTls.cpp


示例16: Attack

bool cGhast::Attack(std::chrono::milliseconds a_Dt)
{
	m_AttackInterval += (static_cast<float>(a_Dt.count()) / 1000) * m_AttackRate;
	
	if ((m_Target != nullptr) && (m_AttackInterval > 3.0))
	{
		// Setting this higher gives us more wiggle room for attackrate
		Vector3d Speed = GetLookVector() * 20;
		Speed.y = Speed.y + 1;
		cGhastFireballEntity * GhastBall = new cGhastFireballEntity(this, GetPosX(), GetPosY() + 1, GetPosZ(), Speed);
		if (GhastBall == nullptr)
		{
			return false;
		}
		if (!GhastBall->Initialize(*m_World))
		{
			delete GhastBall;
			GhastBall = nullptr;
			return false;
		}
		m_World->BroadcastSpawnEntity(*GhastBall);
		m_AttackInterval = 0.0;
		
		return true;
	}
	return false;
}
开发者ID:Nakkar,项目名称:cuberite,代码行数:27,代码来源:Ghast.cpp


示例17: majority

void write_concern::majority(std::chrono::milliseconds timeout) {
    const auto count = timeout.count();
    if ((count < 0) || (count >= std::numeric_limits<std::int32_t>::max()))
        throw logic_error{error_code::k_invalid_parameter};
    libmongoc::write_concern_set_wmajority(_impl->write_concern_t,
                                           static_cast<std::int32_t>(count));
}
开发者ID:xdg,项目名称:mongo-cxx-driver,代码行数:7,代码来源:write_concern.cpp


示例18: Push

void cLuaState::Push(std::chrono::milliseconds a_Value)
{
	ASSERT(IsValid());

	tolua_pushnumber(m_LuaState, static_cast<lua_Number>(a_Value.count()));
	m_NumCurrentFunctionArgs += 1;
}
开发者ID:1285done,项目名称:cuberite,代码行数:7,代码来源:LuaState.cpp


示例19: sleep

void Timer::sleep(std::chrono::milliseconds duration) {
  assert(dispatcher != nullptr);
  assert(context == nullptr);
  if (stopped) {
    throw InterruptedException();
  }

  Dispatcher::OperationContext timerContext;
  timerContext.context = dispatcher->getCurrentContext();
  timerContext.interrupted = false;
  timer = dispatcher->getTimer();

  struct kevent event;
  EV_SET(&event, timer, EVFILT_TIMER, EV_ADD | EV_ENABLE | EV_ONESHOT, 0, duration.count(), &timerContext);

  if (kevent(dispatcher->getKqueue(), &event, 1, NULL, 0, NULL) == -1) {
    throw std::runtime_error("Timer::stop, kevent() failed, errno=" + std::to_string(errno));
  }

  context = &timerContext;
  dispatcher->dispatch();
  assert(dispatcher != nullptr);
  assert(timerContext.context == dispatcher->getCurrentContext());
  assert(context == &timerContext);
  context = nullptr;
  timerContext.context = nullptr;
  dispatcher->pushTimer(timer);
  if (timerContext.interrupted) {
    throw InterruptedException();
  }
}
开发者ID:inmoney,项目名称:bytecoin,代码行数:31,代码来源:Timer.cpp


示例20: locker

std::unique_ptr<MessageDecoder> Connection::sendSyncMessageFromSecondaryThread(uint64_t syncRequestID, std::unique_ptr<MessageEncoder> encoder, std::chrono::milliseconds timeout)
{
    ASSERT(RunLoop::current() != m_clientRunLoop);

    if (!isValid())
        return nullptr;

    SecondaryThreadPendingSyncReply pendingReply;

    // Push the pending sync reply information on our stack.
    {
        MutexLocker locker(m_syncReplyStateMutex);
        if (!m_shouldWaitForSyncReplies)
            return nullptr;

        ASSERT(!m_secondaryThreadPendingSyncReplyMap.contains(syncRequestID));
        m_secondaryThreadPendingSyncReplyMap.add(syncRequestID, &pendingReply);
    }

    sendMessage(std::move(encoder), 0);

    pendingReply.semaphore.wait(currentTime() + (timeout.count() / 1000.0));

    // Finally, pop the pending sync reply information.
    {
        MutexLocker locker(m_syncReplyStateMutex);
        ASSERT(m_secondaryThreadPendingSyncReplyMap.contains(syncRequestID));
        m_secondaryThreadPendingSyncReplyMap.remove(syncRequestID);
    }

    return std::move(pendingReply.replyDecoder);
}
开发者ID:CannedFish,项目名称:webkitgtk,代码行数:32,代码来源:Connection.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ chrono::nanoseconds类代码示例发布时间:2022-05-31
下一篇:
C++ chrono::microseconds类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap