mark a. foltz | cbdea4b | 2019-11-18 16:49:14 -0800 | [diff] [blame] | 1 | // 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 Bayles | c9201dd | 2020-06-02 15:51:31 -0700 | [diff] [blame^] | 9 | #include "util/chrono_helpers.h" |
| 10 | |
mark a. foltz | cbdea4b | 2019-11-18 16:49:14 -0800 | [diff] [blame] | 11 | namespace openscreen { |
mark a. foltz | cbdea4b | 2019-11-18 16:49:14 -0800 | [diff] [blame] | 12 | |
| 13 | struct timeval ToTimeval(const Clock::duration& timeout) { |
| 14 | struct timeval tv; |
Jordan Bayles | c9201dd | 2020-06-02 15:51:31 -0700 | [diff] [blame^] | 15 | const auto whole_seconds = to_seconds(timeout); |
mark a. foltz | cbdea4b | 2019-11-18 16:49:14 -0800 | [diff] [blame] | 16 | tv.tv_sec = whole_seconds.count(); |
Jordan Bayles | c9201dd | 2020-06-02 15:51:31 -0700 | [diff] [blame^] | 17 | tv.tv_usec = to_microseconds(timeout - whole_seconds).count(); |
mark a. foltz | cbdea4b | 2019-11-18 16:49:14 -0800 | [diff] [blame] | 18 | |
| 19 | return tv; |
| 20 | } |
| 21 | |
mark a. foltz | cbdea4b | 2019-11-18 16:49:14 -0800 | [diff] [blame] | 22 | } // namespace openscreen |