blob: 2a79e681f0f2fbc1e2be6be37f9cf403cf989a42 [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
Jordan Baylesc9201dd2020-06-02 15:51:31 -07009#include "util/chrono_helpers.h"
10
mark a. foltzcbdea4b2019-11-18 16:49:14 -080011namespace openscreen {
mark a. foltzcbdea4b2019-11-18 16:49:14 -080012
13struct timeval ToTimeval(const Clock::duration& timeout) {
14 struct timeval tv;
Jordan Baylesc9201dd2020-06-02 15:51:31 -070015 const auto whole_seconds = to_seconds(timeout);
mark a. foltzcbdea4b2019-11-18 16:49:14 -080016 tv.tv_sec = whole_seconds.count();
Jordan Baylesc9201dd2020-06-02 15:51:31 -070017 tv.tv_usec = to_microseconds(timeout - whole_seconds).count();
mark a. foltzcbdea4b2019-11-18 16:49:14 -080018
19 return tv;
20}
21
mark a. foltzcbdea4b2019-11-18 16:49:14 -080022} // namespace openscreen