本文整理汇总了C++中std::chrono::seconds类的典型用法代码示例。如果您正苦于以下问题:C++ seconds类的具体用法?C++ seconds怎么用?C++ seconds使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了seconds类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: invalid_argument
pplx::task<void> cloud_queue::add_message_async(cloud_queue_message& message, std::chrono::seconds time_to_live, std::chrono::seconds initial_visibility_timeout, queue_request_options& options, operation_context context)
{
if (time_to_live.count() <= 0LL)
{
throw std::invalid_argument(protocol::error_non_positive_time_to_live);
}
if (time_to_live.count() > 604800LL)
{
throw std::invalid_argument(protocol::error_large_time_to_live);
}
if (initial_visibility_timeout.count() < 0LL)
{
throw std::invalid_argument(protocol::error_negative_initial_visibility_timeout);
}
if (initial_visibility_timeout.count() > 604800LL)
{
throw std::invalid_argument(protocol::error_large_initial_visibility_timeout);
}
queue_request_options modified_options = get_modified_options(options);
storage_uri uri = protocol::generate_queue_message_uri(service_client(), *this);
std::shared_ptr<core::storage_command<void>> command = std::make_shared<core::storage_command<void>>(uri);
command->set_build_request(std::bind(protocol::add_message, message, time_to_live, initial_visibility_timeout, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
command->set_authentication_handler(service_client().authentication_handler());
command->set_preprocess_response(std::bind(protocol::preprocess_response_void, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
return core::executor<void>::execute_async(command, modified_options, context);
}
示例2: Connect
bool SocketImpl::Connect(const SocketAddress& address, const std::chrono::seconds& timeout /*= std::chrono::seconds(0)*/)
{
if (INVALID_SOCKET == m_sockfd)
Init(AF_INET);
if (timeout.count() > 0)
SetBlocking(false);
bool bResult = false;
do
{
if (SOCKET_ERROR == connect(m_sockfd, address.GetAddress(), address.GetLength()))
{
if (timeout.count() == 0)
break;
int err = WSAGetLastError();
if (WSAEINPROGRESS != err
&& WSAEWOULDBLOCK != err
&& WSAEISCONN != err)
break;
if (!Poll(timeout, SELECT_READ | SELECT_WRITE | SELECT_ERROR))
break;
if (GetSocketError() != 0)
break;
}
bResult = true;
} while (0);
if (timeout.count() > 0)
SetBlocking(true);
return bResult;
}
示例3: check_hysteresis
bool wpa_access_point::check_hysteresis(int new_rssi,int hyst_difference_rssi,int minrssi, std::chrono::seconds& transition_time)
{
lock_guard<mutex> lock(m_locker);
if(m_bHysteresisMode)
{
if(abs(m_rssi - new_rssi) >= hyst_difference_rssi && new_rssi > minrssi && m_rssi > new_rssi) // patch
{
auto current_time = duration_cast<seconds>(system_clock::now().time_since_epoch());
if(current_time.count() - m_HysteresisStartTime.count() >= transition_time.count())
{
cancel_hysteresis();
cout << "[" << m_HysteresisStartTime.count() << "-" << current_time.count() << "]\n";
return true;
}
else
{
return false;
}
}
else
{
cancel_hysteresis();
return false;
}
}
else
{
return false;
}
}
示例4: SetOption
bool SocketImpl::SetOption(int level, int option, const std::chrono::seconds& value)
{
struct timeval tv;
tv.tv_sec = (long)value.count();
tv.tv_usec = 0L;
return SetRawOption(level, option, &tv, sizeof(tv));
}
示例5: SetLinger
void Socket::SetLinger(bool on, const std::chrono::seconds& seconds)
{
struct linger l;
#pragma push_macro("max")
#undef max
std::chrono::milliseconds::rep maxTimespan = std::numeric_limits<decltype(l.l_linger)>::max();
#pragma pop_macro("max")
if (seconds.count() > maxTimespan)
{
/* throw invalid argument */
}
l.l_onoff = on ? 1 : 0;
l.l_linger = static_cast<decltype(l.l_linger)>(seconds.count());
SetOption(SOL_SOCKET, SO_LINGER, reinterpret_cast<const std::int8_t *>(&l), sizeof(l));
}
示例6: add_message
web::http::http_request add_message(const cloud_queue& queue, const cloud_queue_message& message, std::chrono::seconds time_to_live, std::chrono::seconds initial_visibility_timeout, web::http::uri_builder uri_builder, const std::chrono::seconds& timeout, operation_context context)
{
if (time_to_live.count() >= 0LL && time_to_live.count() != 604800LL)
{
uri_builder.append_query(U("messagettl"), time_to_live.count());
}
if (initial_visibility_timeout.count() > 0LL)
{
uri_builder.append_query(U("visibilitytimeout"), initial_visibility_timeout.count());
}
web::http::http_request request = queue_base_request(web::http::methods::POST, uri_builder, timeout, context);
protocol::message_writer writer;
std::string content = writer.write(message.content_as_string());
request.set_body(content);
return request;
}
示例7: base_request
web::http::http_request base_request(web::http::method method, web::http::uri_builder uri_builder, const std::chrono::seconds& timeout, operation_context context)
{
if (timeout.count() > 0)
{
uri_builder.append_query(core::make_query_parameter(uri_query_timeout, timeout.count(), /* do_encoding */ false));
}
web::http::http_request request(method);
request.set_request_uri(uri_builder.to_uri());
web::http::http_headers& headers = request.headers();
headers.add(web::http::header_names::user_agent, header_value_user_agent);
headers.add(ms_header_version, header_value_storage_version);
if (method == web::http::methods::PUT)
{
headers.set_content_length(0);
}
return request;
}
示例8: get_messages
web::http::http_request get_messages(const cloud_queue& queue, size_t message_count, std::chrono::seconds visibility_timeout, bool is_peek, web::http::uri_builder uri_builder, const std::chrono::seconds& timeout, operation_context context)
{
if (is_peek)
{
uri_builder.append_query(U("peekonly=true"));
}
if (message_count > 1U)
{
// The service uses the default value 1
uri_builder.append_query(U("numofmessages"), message_count);
}
if (!is_peek && visibility_timeout.count() > 0LL)
{
uri_builder.append_query(U("visibilitytimeout"), visibility_timeout.count());
}
web::http::http_request request = queue_base_request(web::http::methods::GET, uri_builder, timeout, context);
return request;
}
示例9: can_write
bool file::can_write(std::chrono::seconds s, std::chrono::nanoseconds n)
{
timespec time = { static_cast<std::time_t>(s.count()), static_cast<long>(n.count()) };
fd_set fds;
FD_ZERO(&fds);
FD_SET(_M_fd, &fds);
int count = pselect(_M_fd+1, 0, &fds, 0, &time, nullptr);
if(count == -1) throw errno_error();
return count;
}
示例10: update_message
web::http::http_request update_message(const cloud_queue& queue, const cloud_queue_message& message, std::chrono::seconds visibility_timeout, bool update_contents, web::http::uri_builder uri_builder, const std::chrono::seconds& timeout, operation_context context)
{
uri_builder.append_query(U("popreceipt"), message.pop_receipt());
uri_builder.append_query(U("visibilitytimeout"), visibility_timeout.count());
web::http::http_request request = queue_base_request(web::http::methods::PUT, uri_builder, timeout, context);
if (update_contents)
{
protocol::message_writer writer;
std::string content = writer.write(message.content_as_string());
request.set_body(content);
}
return request;
}
示例11: scheduleAfterDelay
void GMainLoopSource::scheduleAfterDelay(const char* name, std::function<bool ()> function, std::chrono::seconds delay, int priority, std::function<void ()> destroyFunction, GMainContext* context)
{
cancel();
ASSERT(!m_context.source);
m_context = {
adoptGRef(g_timeout_source_new_seconds(delay.count())),
nullptr, // cancellable
nullptr, // socketCancellable
nullptr, // voidCallback
WTF::move(function),
nullptr, // socketCallback
WTF::move(destroyFunction)
};
scheduleTimeoutSource(name, reinterpret_cast<GSourceFunc>(boolSourceCallback), priority, context);
}
示例12: get_messages
web::http::http_request get_messages(size_t message_count, std::chrono::seconds visibility_timeout, bool is_peek, web::http::uri_builder& uri_builder, const std::chrono::seconds& timeout, operation_context context)
{
if (is_peek)
{
uri_builder.append_query(_XPLATSTR("peekonly=true"));
}
if (message_count > 1U)
{
// The service uses the default value 1
uri_builder.append_query(core::make_query_parameter(_XPLATSTR("numofmessages"), message_count, /* do_encoding */ false));
}
if (!is_peek && visibility_timeout.count() > 0LL)
{
uri_builder.append_query(core::make_query_parameter(_XPLATSTR("visibilitytimeout"), visibility_timeout.count(), /* do_encoding */ false));
}
web::http::http_request request = queue_base_request(web::http::methods::GET, uri_builder, timeout, context);
return request;
}
示例13: takeover
int TakeoverAgent::takeover(std::chrono::seconds timeoutSec) {
#ifdef _MSC_VER
return -1;
#else
int ret;
Logger::Info("takeover: beginning listen socket acquisition");
uint8_t fd_request[3] = P_VERSION C_FD_REQ;
uint8_t fd_response[3] = {0,0,0};
uint32_t response_len = sizeof(fd_response);
afdt_error_t err = AFDT_ERROR_T_INIT;
// TODO(dreiss): Make this timeout configurable.
struct timeval timeout = { timeoutSec.count() , 0 };
ret = afdt_sync_client(m_transfer_fname.c_str(),
fd_request,
sizeof(fd_request) - 1,
fd_response,
&response_len,
&m_sock,
&timeout,
&err);
if (ret < 0) {
fd_transfer_error_handler(&err, nullptr);
errno = EADDRINUSE;
return -1;
} else if (m_sock < 0) {
String resp((const char*)fd_response, response_len, CopyString);
Logger::Error("AFDT did not receive a file descriptor: response = '%s'",
HHVM_FN(addcslashes)(resp, null_string).data());
errno = EADDRINUSE;
return -1;
}
Logger::Info("takeover: acquired listen socket");
m_took_over = true;
return m_sock;
#endif
}
示例14: updatePktLenHist
void BcmPort::updatePktLenHist(
std::chrono::seconds now,
stats::ExportedHistogramMapImpl::LockableHistogram* hist,
const std::vector<opennsl_stat_val_t>& stats) {
// Get the counter values
uint64_t counters[10];
// opennsl_stat_multi_get() unfortunately doesn't correctly const qualify
// it's stats arguments right now.
opennsl_stat_val_t* statsArg =
const_cast<opennsl_stat_val_t*>(&stats.front());
auto ret = opennsl_stat_multi_get(unit_, port_,
stats.size(), statsArg, counters);
if (OPENNSL_FAILURE(ret)) {
LOG(ERROR) << "Failed to get packet length stats for port " << port_
<< " :" << opennsl_errmsg(ret);
return;
}
// Update the histogram
auto guard = hist->makeLockGuard();
for (int idx = 0; idx < stats.size(); ++idx) {
hist->addValueLocked(guard, now.count(), idx, counters[idx]);
}
}
示例15:
fcppt::string
fruitlib::human_readable_time_difference(
std::chrono::seconds const &_seconds)
{
typedef
std::chrono::seconds::rep
arithmetic_type;
arithmetic_type const seconds =
_seconds.count();
arithmetic_type const minutes =
seconds / 60;
if(minutes < 2)
return
FCPPT_TEXT("Just now");
if(minutes < 45)
return
fcppt::insert_to_fcppt_string(
minutes)+
FCPPT_TEXT(" minutes ago");
arithmetic_type const hours =
minutes / 60;
if(hours < 2)
return
FCPPT_TEXT("An hour ago");
if(hours < 24)
return
fcppt::insert_to_fcppt_string(
hours)+
FCPPT_TEXT(" hours ago");
arithmetic_type const days =
hours / 24;
if(days < 2)
return
FCPPT_TEXT("A day ago");
if(days < 7)
return
fcppt::insert_to_fcppt_string(
days)+
FCPPT_TEXT(" days ago");
arithmetic_type const weeks =
days / 7;
if(weeks < 2)
return
FCPPT_TEXT("A week ago");
if(weeks < 4)
return
fcppt::insert_to_fcppt_string(
weeks)+
FCPPT_TEXT(" weeks ago");
arithmetic_type const months =
weeks / 4;
if(months < 2)
return
FCPPT_TEXT("A month ago");
if(months < 12)
return
fcppt::insert_to_fcppt_string(
months)+
FCPPT_TEXT(" months ago");
arithmetic_type const years =
months / 12;
if(years < 2)
return
FCPPT_TEXT("A year ago");
return
fcppt::insert_to_fcppt_string(
years)+
FCPPT_TEXT(" years ago");
}