|
3 | 3 | #include <sys/socket.h> |
4 | 4 | #include <sys/types.h> |
5 | 5 | #include <unistd.h> |
6 | | -#include <uv.h> |
7 | 6 | #include <stdexcept> |
| 7 | +#include <chrono> |
8 | 8 |
|
9 | 9 | #include "BluetoothHciSocket.h" |
10 | 10 |
|
| 11 | +static uint64_t highResTimeNs() { |
| 12 | + auto now = std::chrono::steady_clock::now(); |
| 13 | + auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count(); |
| 14 | + return static_cast<uint64_t>(ns); |
| 15 | +} |
| 16 | + |
11 | 17 | BluetoothHciSocket::BluetoothHciSocket(const Napi::CallbackInfo& info) : |
12 | 18 | Napi::ObjectWrap<BluetoothHciSocket>(info), |
13 | 19 | stopFlag(false), |
@@ -344,13 +350,13 @@ bool BluetoothHciSocket::kernelConnectWorkArounds(char * data, int length) { |
344 | 350 | l2socket_ptr = it_connecting->second; |
345 | 351 | l2socket_ptr->disconnect(); |
346 | 352 | l2socket_ptr->connect(); |
347 | | - l2socket_ptr->setExpires(uv_hrtime() + L2_CONNECT_TIMEOUT); |
| 353 | + l2socket_ptr->setExpires(highResTimeNs() + L2_CONNECT_TIMEOUT); |
348 | 354 | } else { |
349 | 355 | // Create a new L2CAP socket and initiate connection |
350 | 356 | bdaddr_t bdaddr_src = {}; |
351 | 357 | memcpy(bdaddr_src.b, _address, sizeof(bdaddr_src.b)); |
352 | 358 |
|
353 | | - uint64_t expires = uv_hrtime() + L2_CONNECT_TIMEOUT; |
| 359 | + uint64_t expires = highResTimeNs() + L2_CONNECT_TIMEOUT; |
354 | 360 |
|
355 | 361 | l2socket_ptr = std::make_shared<BluetoothHciL2Socket> ( |
356 | 362 | this, & bdaddr_src, _addressType, & bdaddr_dst, dst_type, expires); |
@@ -620,7 +626,7 @@ void BluetoothHciSocket::Cleanup(const Napi::CallbackInfo& info) { |
620 | 626 | Napi::Env env = info.Env(); // Get the current efnvironment |
621 | 627 | Napi::HandleScope scope(env); // Create a handle scope for memory management |
622 | 628 |
|
623 | | - auto now = uv_hrtime(); |
| 629 | + auto now = highResTimeNs(); |
624 | 630 |
|
625 | 631 | for (auto it = this->_l2sockets_connecting.cbegin(); it != this->_l2sockets_connecting.cend() /* not hoisted */; /* no increment */) { |
626 | 632 | if (now < it->second->getExpires()) { |
|
0 commit comments