Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/BluetoothHciL2Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <uv.h>
#include <stdexcept>

#include "BluetoothHciL2Socket.h"
Expand Down
14 changes: 10 additions & 4 deletions src/BluetoothHciSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <uv.h>
#include <stdexcept>
#include <chrono>

#include "BluetoothHciSocket.h"

static uint64_t highResTimeNs() {
auto now = std::chrono::steady_clock::now();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
return static_cast<uint64_t>(ns);
}

BluetoothHciSocket::BluetoothHciSocket(const Napi::CallbackInfo& info) :
Napi::ObjectWrap<BluetoothHciSocket>(info),
stopFlag(false),
Expand Down Expand Up @@ -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<BluetoothHciL2Socket> (
this, & bdaddr_src, _addressType, & bdaddr_dst, dst_type, expires);
Expand Down Expand Up @@ -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()) {
Expand Down