Skip to content

Commit

Permalink
Fix/binding offsets, adds back rtoCount (holepunchto#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
jthomas43 authored Sep 11, 2024
1 parent 6af6112 commit e649e12
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,7 @@ NAPI_INIT() {
NAPI_EXPORT_OFFSETOF(udx_stream_t, packets_in)
NAPI_EXPORT_OFFSETOF(udx_stream_t, bytes_out)
NAPI_EXPORT_OFFSETOF(udx_stream_t, packets_out)
NAPI_EXPORT_OFFSETOF(udx_stream_t, rto_count)
NAPI_EXPORT_OFFSETOF(udx_stream_t, retransmit_count)
NAPI_EXPORT_OFFSETOF(udx_stream_t, fast_recovery_count)

Expand Down
11 changes: 8 additions & 3 deletions lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = class UDXStream extends streamx.Duplex {

this._handle = b4a.allocUnsafe(binding.sizeof_udx_napi_stream_t)
this._view = new Uint32Array(this._handle.buffer, this._handle.byteOffset, this._handle.byteLength >> 2)
this._view16 = new Uint16Array(this._handle.buffer, this._handle.byteOffset, this._handle.byteLength >> 1)
this._view64 = new BigUint64Array(this._handle.buffer, this._handle.byteOffset, this._handle.byteLength >> 3)

this._wreqs = []
Expand Down Expand Up @@ -69,7 +70,7 @@ module.exports = class UDXStream extends streamx.Duplex {
}

get mtu () {
return this._view[binding.offsetof_udx_stream_t_mtu >> 2] & 0xffff
return this._view16[binding.offsetof_udx_stream_t_mtu >> 1]
}

get rtt () {
Expand All @@ -80,12 +81,16 @@ module.exports = class UDXStream extends streamx.Duplex {
return this._view[binding.offsetof_udx_stream_t_cwnd >> 2]
}

get rtoCount () {
return this._view16[binding.offsetof_udx_stream_t_rto_count >> 1]
}

get retransmits () {
return this._view[binding.offsetof_udx_stream_t_retransmit_count >> 2] & 0xffff
return this._view16[binding.offsetof_udx_stream_t_retransmit_count >> 1]
}

get fastRecoveries () {
return this._view[binding.offsetof_udx_stream_t_fast_recovery_count >> 2] & 0xffff
return this._view16[binding.offsetof_udx_stream_t_fast_recovery_count >> 1]
}

get inflight () {
Expand Down
7 changes: 3 additions & 4 deletions test/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,10 +865,9 @@ test('UDX - basic stats', async function (t) {
t.is(aUdx.bytesReceived, 0, 'sanity check: init 0')
t.is(aUdx.packetsReceived, 0, 'sanity check: init 0')

// these seem to be consistently 1 at the start, so we don't check for 0
// but just that they exist and are a number
t.is(a.retransmits >= 0, true, 'sanity check: it is a number')
t.is(a.fastRecoveries >= 0, true, 'sanity check: it is a number')
t.is(a.retransmits, 0, 'initialized to zero')
t.is(a.rtoCount, 0, 'initialized to zero')
t.is(a.fastRecoveries, 0, 'initialized to zero')

let aNrDataEvents = 0
a.on('data', function (data) {
Expand Down

0 comments on commit e649e12

Please sign in to comment.