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 | |
| 9 | namespace openscreen { |
| 10 | namespace platform { |
| 11 | |
| 12 | struct 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 |