From 0f6c012b23b9ac111dc1353fb7278620663fd394 Mon Sep 17 00:00:00 2001 From: David Hodo Date: Wed, 22 May 2013 20:31:52 -0500 Subject: [PATCH 1/2] fix bug in time diff on unix --- src/impl/unix.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl/unix.cc b/src/impl/unix.cc index 48b97a3f..7d0c952e 100755 --- a/src/impl/unix.cc +++ b/src/impl/unix.cc @@ -454,7 +454,7 @@ Serial::SerialImpl::read (uint8_t *buf, size_t size) // Calculate the time select took struct timeval diff; diff.tv_sec = end.tv_sec - start.tv_sec; - diff.tv_usec = static_cast ((end.tv_nsec - start.tv_nsec) / 1000); + diff.tv_usec = static_cast (((end.tv_nsec+diff.tv_sec*1000000000) - start.tv_nsec) / 1000); // Update the timeout if (total_timeout.tv_sec <= diff.tv_sec) { total_timeout.tv_sec = 0; From dc7a59f329c0d13f351964a1f4b5fc3ae534c4b8 Mon Sep 17 00:00:00 2001 From: David Hodo Date: Wed, 22 May 2013 20:36:54 -0500 Subject: [PATCH 2/2] fix time diff bug for write as well --- src/impl/unix.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl/unix.cc b/src/impl/unix.cc index 7d0c952e..24d54821 100755 --- a/src/impl/unix.cc +++ b/src/impl/unix.cc @@ -554,7 +554,7 @@ Serial::SerialImpl::write (const uint8_t *data, size_t length) // Calculate the time select took struct timeval diff; diff.tv_sec = end.tv_sec - start.tv_sec; - diff.tv_usec = static_cast ((end.tv_nsec - start.tv_nsec) / 1000); + diff.tv_usec = static_cast (((end.tv_nsec+diff.tv_sec*1000000000) - start.tv_nsec) / 1000); // Update the timeout if (timeout.tv_sec <= diff.tv_sec) { timeout.tv_sec = 0;