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


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

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


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


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