diff --git a/src/BluetoothHciL2Socket.cpp b/src/BluetoothHciL2Socket.cpp index a6f4b84..c1bc2d4 100644 --- a/src/BluetoothHciL2Socket.cpp +++ b/src/BluetoothHciL2Socket.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include "BluetoothHciL2Socket.h" diff --git a/src/BluetoothHciSocket.cpp b/src/BluetoothHciSocket.cpp index c258685..dd0cb2f 100644 --- a/src/BluetoothHciSocket.cpp +++ b/src/BluetoothHciSocket.cpp @@ -3,11 +3,17 @@ #include #include #include -#include #include +#include #include "BluetoothHciSocket.h" +static uint64_t highResTimeNs() { + auto now = std::chrono::steady_clock::now(); + auto ns = std::chrono::duration_cast(now.time_since_epoch()).count(); + return static_cast(ns); +} + BluetoothHciSocket::BluetoothHciSocket(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info), stopFlag(false), @@ -344,13 +350,13 @@ bool BluetoothHciSocket::kernelConnectWorkArounds(char * data, int length) { l2socket_ptr = it_connecting->second; l2socket_ptr->disconnect(); l2socket_ptr->connect(); - l2socket_ptr->setExpires(uv_hrtime() + L2_CONNECT_TIMEOUT); + l2socket_ptr->setExpires(highResTimeNs() + L2_CONNECT_TIMEOUT); } else { // Create a new L2CAP socket and initiate connection bdaddr_t bdaddr_src = {}; memcpy(bdaddr_src.b, _address, sizeof(bdaddr_src.b)); - uint64_t expires = uv_hrtime() + L2_CONNECT_TIMEOUT; + uint64_t expires = highResTimeNs() + L2_CONNECT_TIMEOUT; l2socket_ptr = std::make_shared ( this, & bdaddr_src, _addressType, & bdaddr_dst, dst_type, expires); @@ -620,7 +626,7 @@ void BluetoothHciSocket::Cleanup(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); // Get the current efnvironment Napi::HandleScope scope(env); // Create a handle scope for memory management - auto now = uv_hrtime(); + auto now = highResTimeNs(); for (auto it = this->_l2sockets_connecting.cbegin(); it != this->_l2sockets_connecting.cend() /* not hoisted */; /* no increment */) { if (now < it->second->getExpires()) {