diff options
author | Jordan Bayles <jophba@chromium.org> | 2020-05-15 17:08:11 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-05-18 17:39:18 +0000 |
commit | ca609c305ed10d10cc2f8c07e772f17d5f94f474 (patch) | |
tree | 4e36a1ce3c9877237f4dab4d4bba58d5919fb1c8 /osp | |
parent | 4a4a818a80ec7af2e03592818a624553f23eb9ef (diff) | |
download | openscreen-ca609c305ed10d10cc2f8c07e772f17d5f94f474.tar.gz |
Time and clock::duration cleanups
This patch contains a few minor time-related cleanups:
1. Instead of having using statements literally everywhere, moved to
using statements for common std::chrono types in the trivial clock
traits header.
2. Removed some Clock::duration types in favor of
std::chrono::milliseconds, because Clock::duration is frequently used
incorrectly--it's microseconds, not milliseconds, so typical
instantiation values of 50 are essentially 0 seconds.
Change-Id: If2b30ca7605bf40165dfb6e76f8386ffa1c0eb87
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/2204429
Reviewed-by: Ryan Keane <rwkeane@google.com>
Commit-Queue: Jordan Bayles <jophba@chromium.org>
Diffstat (limited to 'osp')
-rw-r--r-- | osp/demo/osp_demo.cc | 5 | ||||
-rw-r--r-- | osp/impl/discovery/mdns/mdns_demo.cc | 5 | ||||
-rw-r--r-- | osp/impl/discovery/mdns/mdns_responder_platform.cc | 12 | ||||
-rw-r--r-- | osp/impl/presentation/presentation_controller_unittest.cc | 1 | ||||
-rw-r--r-- | osp/impl/presentation/url_availability_requester_unittest.cc | 3 |
5 files changed, 17 insertions, 9 deletions
diff --git a/osp/demo/osp_demo.cc b/osp/demo/osp_demo.cc index c14c7f29..9b7604e6 100644 --- a/osp/demo/osp_demo.cc +++ b/osp/demo/osp_demo.cc @@ -415,7 +415,7 @@ void RunControllerPollLoop(Controller* controller) { request_delegate.connection->Terminate( TerminationReason::kControllerTerminateCalled); } - }; + } watch = Controller::ReceiverWatch(); } @@ -644,7 +644,8 @@ int main(int argc, char** argv) { // TODO(jophba): Mac on Mojave hangs on this command forever. openscreen::SetLogFifoOrDie(log_filename); - PlatformClientPosix::Create(Clock::duration{50}, Clock::duration{50}); + PlatformClientPosix::Create(std::chrono::milliseconds{50}, + std::chrono::milliseconds{50}); if (is_receiver_demo) { OSP_LOG_INFO << "Running publisher demo..."; diff --git a/osp/impl/discovery/mdns/mdns_demo.cc b/osp/impl/discovery/mdns/mdns_demo.cc index a6c0e508..ddfd0742 100644 --- a/osp/impl/discovery/mdns/mdns_demo.cc +++ b/osp/impl/discovery/mdns/mdns_demo.cc @@ -58,7 +58,7 @@ struct Service { class DemoSocketClient : public UdpSocket::Client { public: - DemoSocketClient(MdnsResponderAdapterImpl* mdns) : mdns_(mdns) {} + explicit DemoSocketClient(MdnsResponderAdapterImpl* mdns) : mdns_(mdns) {} void OnError(UdpSocket* socket, Error error) override { // TODO(crbug.com/openscreen/66): Change to OSP_LOG_FATAL. @@ -361,7 +361,8 @@ int main(int argc, char** argv) { openscreen::osp::ServiceMap services; openscreen::osp::g_services = &services; - PlatformClientPosix::Create(Clock::duration{50}, Clock::duration{50}); + PlatformClientPosix::Create(std::chrono::milliseconds{50}, + std::chrono::milliseconds{50}); openscreen::osp::BrowseDemo( PlatformClientPosix::GetInstance()->GetTaskRunner(), labels[0], labels[1], diff --git a/osp/impl/discovery/mdns/mdns_responder_platform.cc b/osp/impl/discovery/mdns/mdns_responder_platform.cc index 02fa9ba6..0d31b2b8 100644 --- a/osp/impl/discovery/mdns/mdns_responder_platform.cc +++ b/osp/impl/discovery/mdns/mdns_responder_platform.cc @@ -18,11 +18,15 @@ #include "third_party/mDNSResponder/src/mDNSCore/mDNSEmbeddedAPI.h" #include "util/osp_logging.h" +namespace { + using std::chrono::duration_cast; using std::chrono::hours; using std::chrono::milliseconds; using std::chrono::seconds; +} // namespace + extern "C" { const char ProgramName[] = "openscreen"; @@ -73,7 +77,13 @@ void mDNSPlatformLock(const mDNS* m) { void mDNSPlatformUnlock(const mDNS* m) {} void mDNSPlatformStrCopy(void* dst, const void* src) { - std::strcpy(static_cast<char*>(dst), static_cast<const char*>(src)); + const char* source = static_cast<const char*>(src); + const size_t source_len = strlen(source); + + // Unfortunately, the caller is responsible for making sure that dst + // if of sufficient length to store the src string. Otherwise we may + // cause an access violation. + std::strncpy(static_cast<char*>(dst), source, source_len); } mDNSu32 mDNSPlatformStrLen(const void* src) { diff --git a/osp/impl/presentation/presentation_controller_unittest.cc b/osp/impl/presentation/presentation_controller_unittest.cc index bad4c666..7e0ca3f2 100644 --- a/osp/impl/presentation/presentation_controller_unittest.cc +++ b/osp/impl/presentation/presentation_controller_unittest.cc @@ -21,7 +21,6 @@ namespace openscreen { namespace osp { -using std::chrono::seconds; using ::testing::_; using ::testing::Invoke; using ::testing::NiceMock; diff --git a/osp/impl/presentation/url_availability_requester_unittest.cc b/osp/impl/presentation/url_availability_requester_unittest.cc index 4b601b38..c1a1fa2c 100644 --- a/osp/impl/presentation/url_availability_requester_unittest.cc +++ b/osp/impl/presentation/url_availability_requester_unittest.cc @@ -17,9 +17,6 @@ #include "platform/test/fake_task_runner.h" #include "util/osp_logging.h" -using std::chrono::milliseconds; -using std::chrono::seconds; - namespace openscreen { namespace osp { |