blob: dd16532421a010937bd68de88f6efc66d6d6a31c [file] [log] [blame]
mark a. foltzcbdea4b2019-11-18 16:49:14 -08001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "platform/impl/timeval_posix.h"
6
7#include <chrono>
8
9namespace openscreen {
10namespace platform {
11
12struct timeval ToTimeval(const Clock::duration& timeout) {
13 struct timeval tv;
14 const auto whole_seconds =
15 std::chrono::duration_cast<std::chrono::seconds>(timeout);
16 tv.tv_sec = whole_seconds.count();
17 tv.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(
18 timeout - whole_seconds)
19 .count();
20
21 return tv;
22}
23
24} // namespace platform
25} // namespace openscreen