blob: 28c25ffe288106c8f93880de03ffba5ba0040af3 [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 {
mark a. foltzcbdea4b2019-11-18 16:49:14 -080010
11struct timeval ToTimeval(const Clock::duration& timeout) {
12 struct timeval tv;
13 const auto whole_seconds =
14 std::chrono::duration_cast<std::chrono::seconds>(timeout);
15 tv.tv_sec = whole_seconds.count();
16 tv.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(
17 timeout - whole_seconds)
18 .count();
19
20 return tv;
21}
22
mark a. foltzcbdea4b2019-11-18 16:49:14 -080023} // namespace openscreen