@fails-components/webtransport 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +42 -111
- package/build.js +4 -4
- package/dist/lib/dom.d.ts +6 -0
- package/dist/lib/dom.d.ts.map +1 -1
- package/dist/lib/event-loop.d.ts +8 -3
- package/dist/lib/event-loop.d.ts.map +1 -1
- package/dist/lib/server.d.ts +3 -2
- package/dist/lib/server.d.ts.map +1 -1
- package/dist/lib/session.d.ts +78 -18
- package/dist/lib/session.d.ts.map +1 -1
- package/dist/lib/stream.d.ts +13 -5
- package/dist/lib/stream.d.ts.map +1 -1
- package/dist/lib/transport.d.ts.map +1 -1
- package/dist/lib/types.d.ts +11 -2
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/webtransport.d.ts +22 -0
- package/dist/lib/webtransport.d.ts.map +1 -1
- package/dist/test/bidirectional-streams.spec.d.ts.map +1 -1
- package/dist/test/datagrams.spec.d.ts.map +1 -1
- package/dist/test/fixtures/p-timeout.d.ts +8 -0
- package/dist/test/fixtures/p-timeout.d.ts.map +1 -0
- package/dist/test/fixtures/read-stream.d.ts.map +1 -1
- package/dist/test/unidirectional-streams.spec.d.ts.map +1 -1
- package/lib/dom.ts +7 -2
- package/lib/event-loop.js +13 -7
- package/lib/server.js +1 -1
- package/lib/session.js +71 -21
- package/lib/stream.js +137 -12
- package/lib/transport.js +3 -1
- package/lib/types.ts +13 -2
- package/lib/webtransport.js +31 -0
- package/package.json +5 -4
- package/platform/base/strings/utf_ostream_operators.h +5 -0
- package/platform/quiche/quic/core/io/socket_win.inc +3 -0
- package/platform/quiche_platform_impl/quiche_command_line_flags_impl.h +7 -0
- package/platform/quiche_platform_impl/quiche_export_impl.h +3 -9
- package/platform/quiche_platform_impl/quiche_server_stats_impl.h +1 -22
- package/platform/quiche_platform_impl/quiche_stream_buffer_allocator_impl.h +1 -4
- package/platform/quiche_platform_impl/quiche_time_utils_impl.h +1 -13
- package/platform/quiche_platform_impl/quiche_udp_socket_platform_impl.h +9 -0
- package/readme.md +3 -1
- package/src/http3client.cc +13 -29
- package/src/http3client.h +2 -6
- package/src/http3clientsession.cc +51 -40
- package/src/http3clientsession.h +44 -31
- package/src/http3clientstream.cc +17 -0
- package/src/http3clientstream.h +10 -0
- package/src/http3eventloop.cc +81 -61
- package/src/http3eventloop.h +10 -7
- package/src/http3server.cc +1 -1
- package/src/http3serversession.cc +1 -136
- package/src/http3serversession.h +7 -77
- package/src/http3serverstream.cc +0 -49
- package/src/http3serverstream.h +0 -5
- package/src/http3wtsessionvisitor.cc +1 -1
- package/src/http3wtsessionvisitor.h +24 -37
- package/src/http3wtstreamvisitor.cc +35 -8
- package/src/http3wtstreamvisitor.h +81 -3
- package/test/bidirectional-streams.spec.js +16 -7
- package/test/datagrams.spec.js +31 -20
- package/test/fixtures/p-timeout.js +33 -0
- package/test/fixtures/read-stream.js +4 -1
- package/test/unidirectional-streams.spec.js +24 -15
- package/platform/net/quiche/common/platform/impl/quiche_flags_impl.h +0 -12
- package/platform/poll.h +0 -2
- package/platform/quiche/quic/core/io/quic_poll_event_loop.h +0 -8
- package/platform/quiche_platform_impl/quic_testvalue_impl.h +0 -19
- package/platform/quiche_platform_impl/quic_udp_socket_winsock.cc +0 -732
- package/platform/quiche_platform_impl/quiche_time_utils_impl.cc +0 -43
- package/platform/quiche_platform_impl/socket_winsock.cc +0 -535
|
@@ -34,7 +34,15 @@ namespace quic
|
|
|
34
34
|
friend Http3WTStreamJS;
|
|
35
35
|
|
|
36
36
|
public:
|
|
37
|
-
Http3WTStream(WebTransportStream *stream, Http3EventLoop *eventloop) :
|
|
37
|
+
Http3WTStream(WebTransportStream *stream, Http3EventLoop *eventloop) :
|
|
38
|
+
stream_(stream),
|
|
39
|
+
eventloop_(eventloop),
|
|
40
|
+
js_(nullptr),
|
|
41
|
+
readpos_(0),
|
|
42
|
+
writepos_(0),
|
|
43
|
+
bufferlen_(0),
|
|
44
|
+
readbufsize_(0),
|
|
45
|
+
readbufdata_(nullptr)
|
|
38
46
|
{
|
|
39
47
|
}
|
|
40
48
|
|
|
@@ -90,10 +98,16 @@ namespace quic
|
|
|
90
98
|
}
|
|
91
99
|
}
|
|
92
100
|
|
|
101
|
+
|
|
102
|
+
inline bool readBufferFull() {
|
|
103
|
+
return !readbufdata_ || bufferlen_ >= readbufsize_;
|
|
104
|
+
}
|
|
105
|
+
|
|
93
106
|
void tryRead()
|
|
94
107
|
{
|
|
95
108
|
pause_reading_ = false;
|
|
96
|
-
if (stream_ && ((stream_->ReadableBytes() > 0) || can_read_pending_)
|
|
109
|
+
if (stream_ && ((stream_->ReadableBytes() > 0) || can_read_pending_)
|
|
110
|
+
&& !readBufferFull())
|
|
97
111
|
{
|
|
98
112
|
can_read_pending_ = false;
|
|
99
113
|
doCanRead();
|
|
@@ -113,6 +127,17 @@ namespace quic
|
|
|
113
127
|
return !stream_;
|
|
114
128
|
}
|
|
115
129
|
|
|
130
|
+
void setReadBuffer(void * data, size_t length) {
|
|
131
|
+
std::function<void()> task = [this, data, length]()
|
|
132
|
+
{
|
|
133
|
+
readbufsize_ = length;
|
|
134
|
+
readbufdata_ = data;
|
|
135
|
+
tryRead();
|
|
136
|
+
};
|
|
137
|
+
eventloop_->Schedule(task);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
116
141
|
protected:
|
|
117
142
|
// internal functions called by js object
|
|
118
143
|
void startReadingInt()
|
|
@@ -137,6 +162,13 @@ namespace quic
|
|
|
137
162
|
eventloop_->Schedule(task);
|
|
138
163
|
}
|
|
139
164
|
|
|
165
|
+
void updateReadPosIntJS(size_t readbytes, uint32_t readpos)
|
|
166
|
+
{
|
|
167
|
+
std::function<void()> task = [this, readpos, readbytes]()
|
|
168
|
+
{ updateReadPosInt(readbytes, readpos); };
|
|
169
|
+
eventloop_->Schedule(task);
|
|
170
|
+
}
|
|
171
|
+
|
|
140
172
|
void streamFinalInt()
|
|
141
173
|
{
|
|
142
174
|
std::function<void()> task = [this]()
|
|
@@ -202,6 +234,17 @@ namespace quic
|
|
|
202
234
|
tryWrite();
|
|
203
235
|
}
|
|
204
236
|
|
|
237
|
+
void updateReadPosInt(size_t readbytes, uint32_t readpos)
|
|
238
|
+
{
|
|
239
|
+
if (!stream_)
|
|
240
|
+
{
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
readpos_ = readpos;
|
|
244
|
+
bufferlen_ -= readbytes;
|
|
245
|
+
tryRead();
|
|
246
|
+
}
|
|
247
|
+
|
|
205
248
|
void cancelWrite(Napi::ObjectReference *handle);
|
|
206
249
|
|
|
207
250
|
private:
|
|
@@ -217,6 +260,13 @@ namespace quic
|
|
|
217
260
|
bool can_read_pending_ = false;
|
|
218
261
|
bool stream_was_reset_ = false;
|
|
219
262
|
std::deque<WChunks> chunks_;
|
|
263
|
+
|
|
264
|
+
//reading stream
|
|
265
|
+
uint32_t readpos_;
|
|
266
|
+
uint32_t writepos_;
|
|
267
|
+
uint32_t bufferlen_;
|
|
268
|
+
size_t readbufsize_;
|
|
269
|
+
void * readbufdata_;
|
|
220
270
|
};
|
|
221
271
|
|
|
222
272
|
class Http3WTStreamJS : public Napi::ObjectWrap<Http3WTStreamJS>, public LifetimeHelper
|
|
@@ -254,6 +304,31 @@ namespace quic
|
|
|
254
304
|
wtstream_->writeChunkIntJS(buffer, len, bufferhandle);
|
|
255
305
|
}
|
|
256
306
|
|
|
307
|
+
void updateReadPos(const Napi::CallbackInfo &info)
|
|
308
|
+
{
|
|
309
|
+
// ok we have to get the buffer
|
|
310
|
+
uint32_t readpos = 0;
|
|
311
|
+
size_t readbytes = 0;
|
|
312
|
+
|
|
313
|
+
if (!info[0].IsUndefined())
|
|
314
|
+
{
|
|
315
|
+
Napi::Number readbytesl = info[0].ToNumber();
|
|
316
|
+
readbytes = readbytesl.Uint32Value();
|
|
317
|
+
} else {
|
|
318
|
+
return Napi::Error::New(Env(), "No readbytes passed").ThrowAsJavaScriptException();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (!info[1].IsUndefined())
|
|
322
|
+
{
|
|
323
|
+
Napi::Number readposl = info[1].ToNumber();
|
|
324
|
+
readpos = readposl.Uint32Value();
|
|
325
|
+
} else {
|
|
326
|
+
return Napi::Error::New(Env(), "No readpos passed").ThrowAsJavaScriptException();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
wtstream_->updateReadPosIntJS(readbytes, readpos);
|
|
330
|
+
}
|
|
331
|
+
|
|
257
332
|
void streamFinal(const Napi::CallbackInfo &info)
|
|
258
333
|
{
|
|
259
334
|
wtstream_->streamFinalInt();
|
|
@@ -292,9 +367,12 @@ namespace quic
|
|
|
292
367
|
DefineClass(env, "Http3WTStreamVisitor",
|
|
293
368
|
{InstanceMethod<&Http3WTStreamJS::writeChunk>("writeChunk",
|
|
294
369
|
static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
370
|
+
InstanceMethod<&Http3WTStreamJS::updateReadPos>("updateReadPos",
|
|
371
|
+
static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
295
372
|
InstanceMethod<&Http3WTStreamJS::resetStream>("resetStream",
|
|
296
373
|
static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
297
|
-
InstanceMethod<&Http3WTStreamJS::stopSending>("stopSending", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
374
|
+
InstanceMethod<&Http3WTStreamJS::stopSending>("stopSending", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
375
|
+
InstanceMethod<&Http3WTStreamJS::streamFinal>("streamFinal", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
298
376
|
InstanceMethod<&Http3WTStreamJS::startReading>("startReading",
|
|
299
377
|
static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
300
378
|
InstanceMethod<&Http3WTStreamJS::stopReading>("stopReading",
|
|
@@ -7,6 +7,7 @@ import { expect } from './fixtures/chai.js'
|
|
|
7
7
|
import { readStream } from './fixtures/read-stream.js'
|
|
8
8
|
import { writeStream } from './fixtures/write-stream.js'
|
|
9
9
|
import { defer } from '../lib/utils.js'
|
|
10
|
+
import * as ui8 from 'uint8arrays'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @template T
|
|
@@ -43,6 +44,7 @@ describe('bidirectional streams', function () {
|
|
|
43
44
|
url = `https://${address.host}:${address.port}`
|
|
44
45
|
})
|
|
45
46
|
|
|
47
|
+
// @ts-ignore
|
|
46
48
|
afterEach(async () => {
|
|
47
49
|
if (client != null) {
|
|
48
50
|
client.close()
|
|
@@ -59,6 +61,7 @@ describe('bidirectional streams', function () {
|
|
|
59
61
|
// server context - waits for the client to open a bidi stream and pipes it back to them
|
|
60
62
|
Promise.resolve().then(async () => {
|
|
61
63
|
const session = await getReaderValue(server.sessionStream(SERVER_PATH))
|
|
64
|
+
if (!session) throw new Error('Got no session')
|
|
62
65
|
const bidiStream = await getReaderValue(
|
|
63
66
|
session.incomingBidirectionalStreams
|
|
64
67
|
)
|
|
@@ -86,9 +89,9 @@ describe('bidirectional streams', function () {
|
|
|
86
89
|
const stream = await client.createBidirectionalStream()
|
|
87
90
|
await writeStream(stream.writable, input)
|
|
88
91
|
|
|
89
|
-
const output = await readStream(stream.readable)
|
|
90
|
-
expect(output).to.deep.equal(
|
|
91
|
-
input,
|
|
92
|
+
const output = await readStream(stream.readable, ui8.concat(input).length)
|
|
93
|
+
expect(ui8.concat(output)).to.deep.equal(
|
|
94
|
+
ui8.concat(input),
|
|
92
95
|
'Did not receive the same bytes we sent'
|
|
93
96
|
)
|
|
94
97
|
})
|
|
@@ -106,12 +109,14 @@ describe('bidirectional streams', function () {
|
|
|
106
109
|
// server context - waits for the client to connect, opens a bidi stream, sends some data and reads the response
|
|
107
110
|
Promise.resolve().then(async () => {
|
|
108
111
|
const session = await getReaderValue(server.sessionStream(SERVER_PATH))
|
|
112
|
+
if (!session) throw new Error('Got no session')
|
|
109
113
|
const stream = await session.createBidirectionalStream()
|
|
110
114
|
|
|
111
115
|
await writeStream(stream.writable, input)
|
|
112
116
|
|
|
113
|
-
const output = await readStream(stream.readable)
|
|
117
|
+
const output = await readStream(stream.readable, ui8.concat(input).length)
|
|
114
118
|
serverData.resolve(output)
|
|
119
|
+
await stream.readable.cancel() // cancel so that the client can progress
|
|
115
120
|
})
|
|
116
121
|
|
|
117
122
|
// client context - waits for the server to open a bidi stream then pipes it back to them
|
|
@@ -127,11 +132,15 @@ describe('bidirectional streams', function () {
|
|
|
127
132
|
|
|
128
133
|
const bidiStream = await getReaderValue(client.incomingBidirectionalStreams)
|
|
129
134
|
// redirect input to output
|
|
130
|
-
|
|
135
|
+
try {
|
|
136
|
+
await bidiStream.readable.pipeTo(bidiStream.writable)
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.log('Pipe to error (ignore)', error) // Actually all you can get is, that the fin is catched
|
|
139
|
+
}
|
|
131
140
|
|
|
132
141
|
const received = await serverData.promise
|
|
133
|
-
expect(received).to.deep.equal(
|
|
134
|
-
input,
|
|
142
|
+
expect(ui8.concat(received)).to.deep.equal(
|
|
143
|
+
ui8.concat(input),
|
|
135
144
|
'Did not receive the same bytes we sent'
|
|
136
145
|
)
|
|
137
146
|
})
|
package/test/datagrams.spec.js
CHANGED
|
@@ -6,7 +6,8 @@ import { WebTransport } from '../lib/index.js'
|
|
|
6
6
|
import { expect } from './fixtures/chai.js'
|
|
7
7
|
import { readStream } from './fixtures/read-stream.js'
|
|
8
8
|
import { writeStream } from './fixtures/write-stream.js'
|
|
9
|
-
import
|
|
9
|
+
import * as ui8 from 'uint8arrays'
|
|
10
|
+
import { pTimeout } from './fixtures/p-timeout.js'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @template T
|
|
@@ -39,6 +40,7 @@ describe('datagrams', function () {
|
|
|
39
40
|
url = `https://${address.host}:${address.port}`
|
|
40
41
|
})
|
|
41
42
|
|
|
43
|
+
// @ts-ignore
|
|
42
44
|
afterEach(async () => {
|
|
43
45
|
if (client != null) {
|
|
44
46
|
client.close()
|
|
@@ -79,7 +81,10 @@ describe('datagrams', function () {
|
|
|
79
81
|
|
|
80
82
|
await writeStream(client.datagrams.writable, input)
|
|
81
83
|
|
|
82
|
-
const output = await readStream(
|
|
84
|
+
const output = await readStream(
|
|
85
|
+
client.datagrams.readable,
|
|
86
|
+
ui8.concat(input).length
|
|
87
|
+
)
|
|
83
88
|
expect(output).to.deep.equal(
|
|
84
89
|
input,
|
|
85
90
|
'Did not receive the same bytes we sent'
|
|
@@ -88,25 +93,29 @@ describe('datagrams', function () {
|
|
|
88
93
|
|
|
89
94
|
it('receives datagrams from the server', async () => {
|
|
90
95
|
this.timeout(200)
|
|
91
|
-
/** @type {Deferred<Uint8Array[]>} */
|
|
92
|
-
const serverData = defer()
|
|
93
|
-
const input = [
|
|
94
|
-
Uint8Array.from([0, 1, 2, 3, 4]),
|
|
95
|
-
Uint8Array.from([5, 6, 7, 8, 9]),
|
|
96
|
-
Uint8Array.from([10, 11, 12, 13, 14])
|
|
97
|
-
]
|
|
98
96
|
|
|
99
97
|
// server context - waits for the client to connect, sends some datagrams and reads the response
|
|
100
98
|
Promise.resolve().then(async () => {
|
|
101
99
|
const session = await getReaderValue(server.sessionStream(SERVER_PATH))
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
let closed = false
|
|
102
|
+
const writer = session.datagrams.writable.getWriter()
|
|
103
|
+
Promise.resolve().then(async () => {
|
|
104
|
+
// eslint-disable-next-line no-unmodified-loop-condition
|
|
105
|
+
while (!closed) {
|
|
106
|
+
try {
|
|
107
|
+
await writer.ready
|
|
108
|
+
await writer.write(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
109
|
+
await new Promise((resolve) => setTimeout(resolve, 1)) // do not flood everything
|
|
110
|
+
} catch {
|
|
111
|
+
// the session can be closed while we are writing
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
})
|
|
106
115
|
|
|
107
116
|
// have to close the session to end the client's datagram stream
|
|
108
|
-
session.
|
|
109
|
-
|
|
117
|
+
await session.closed
|
|
118
|
+
closed = true
|
|
110
119
|
})
|
|
111
120
|
|
|
112
121
|
// client context - pipes the server's datagrams back to them
|
|
@@ -120,13 +129,15 @@ describe('datagrams', function () {
|
|
|
120
129
|
})
|
|
121
130
|
await client.ready
|
|
122
131
|
|
|
123
|
-
//
|
|
124
|
-
|
|
132
|
+
// datagram transport is unreliable, at least one message should make it through
|
|
133
|
+
const expected = 1
|
|
125
134
|
|
|
126
|
-
const received = await
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
'Did not receive the same bytes we sent'
|
|
135
|
+
const received = await pTimeout(
|
|
136
|
+
readStream(client.datagrams.readable, expected),
|
|
137
|
+
1000
|
|
130
138
|
)
|
|
139
|
+
await client.close()
|
|
140
|
+
client = undefined
|
|
141
|
+
expect(received).to.have.lengthOf(expected)
|
|
131
142
|
})
|
|
132
143
|
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class TimeoutError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} message
|
|
4
|
+
*/
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message)
|
|
7
|
+
|
|
8
|
+
this.name = this[Symbol.toStringTag] = 'TimeoutError'
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @template T
|
|
14
|
+
* @param {Promise<T>} promise
|
|
15
|
+
* @param {number} timeout
|
|
16
|
+
* @returns {Promise<T>}
|
|
17
|
+
*/
|
|
18
|
+
export async function pTimeout(promise, timeout) {
|
|
19
|
+
let ref
|
|
20
|
+
|
|
21
|
+
const value = await Promise.race([
|
|
22
|
+
promise,
|
|
23
|
+
new Promise((resolve, reject) => {
|
|
24
|
+
ref = setTimeout(() => {
|
|
25
|
+
reject(new TimeoutError('timeout'))
|
|
26
|
+
}, timeout)
|
|
27
|
+
})
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
clearTimeout(ref)
|
|
31
|
+
|
|
32
|
+
return value
|
|
33
|
+
}
|
|
@@ -12,6 +12,7 @@ export async function readStream(readable, expected) {
|
|
|
12
12
|
try {
|
|
13
13
|
/** @type {T[]} */
|
|
14
14
|
const output = []
|
|
15
|
+
let outputlength = 0
|
|
15
16
|
|
|
16
17
|
while (true) {
|
|
17
18
|
const { done, value } = await reader.read()
|
|
@@ -21,10 +22,12 @@ export async function readStream(readable, expected) {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
if (value != null) {
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
outputlength += value.length
|
|
24
27
|
output.push(value)
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
if (expected != null &&
|
|
30
|
+
if (expected != null && outputlength >= expected) {
|
|
28
31
|
break
|
|
29
32
|
}
|
|
30
33
|
}
|
|
@@ -7,6 +7,7 @@ import { expect } from 'chai'
|
|
|
7
7
|
import { readStream } from './fixtures/read-stream.js'
|
|
8
8
|
import { writeStream } from './fixtures/write-stream.js'
|
|
9
9
|
import { defer } from '../lib/utils.js'
|
|
10
|
+
import * as ui8 from 'uint8arrays'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @template T
|
|
@@ -39,6 +40,7 @@ describe('unidirectional streams', function () {
|
|
|
39
40
|
url = `https://${address.host}:${address.port}`
|
|
40
41
|
})
|
|
41
42
|
|
|
43
|
+
// @ts-ignore
|
|
42
44
|
afterEach(async () => {
|
|
43
45
|
if (client != null) {
|
|
44
46
|
client.close()
|
|
@@ -55,13 +57,21 @@ describe('unidirectional streams', function () {
|
|
|
55
57
|
/** @type {Deferred<Uint8Array[]>} */
|
|
56
58
|
const serverData = defer()
|
|
57
59
|
|
|
60
|
+
const input = [
|
|
61
|
+
Uint8Array.from([0, 1, 2, 3, 4]),
|
|
62
|
+
Uint8Array.from([5, 6, 7, 8, 9]),
|
|
63
|
+
Uint8Array.from([10, 11, 12, 13, 14])
|
|
64
|
+
]
|
|
65
|
+
|
|
58
66
|
// server context - waits for the client to open a bidi stream and pipes it back to them
|
|
59
67
|
Promise.resolve().then(async () => {
|
|
60
68
|
const session = await getReaderValue(server.sessionStream(SERVER_PATH))
|
|
69
|
+
if (!session) throw new Error('no session')
|
|
61
70
|
const stream = await getReaderValue(session.incomingUnidirectionalStreams)
|
|
62
71
|
|
|
63
|
-
const output = await readStream(stream)
|
|
72
|
+
const output = await readStream(stream, ui8.concat(input).length)
|
|
64
73
|
serverData.resolve(output)
|
|
74
|
+
await stream.cancel() // cancel so that the client can progress
|
|
65
75
|
})
|
|
66
76
|
|
|
67
77
|
// client context - connects to the server, opens a bidi stream, sends some data and reads the response
|
|
@@ -75,18 +85,12 @@ describe('unidirectional streams', function () {
|
|
|
75
85
|
})
|
|
76
86
|
await client.ready
|
|
77
87
|
|
|
78
|
-
const input = [
|
|
79
|
-
Uint8Array.from([0, 1, 2, 3, 4]),
|
|
80
|
-
Uint8Array.from([5, 6, 7, 8, 9]),
|
|
81
|
-
Uint8Array.from([10, 11, 12, 13, 14])
|
|
82
|
-
]
|
|
83
|
-
|
|
84
88
|
const stream = await client.createUnidirectionalStream()
|
|
85
89
|
await writeStream(stream, input)
|
|
86
90
|
|
|
87
91
|
const received = await serverData.promise
|
|
88
|
-
expect(received).to.deep.equal(
|
|
89
|
-
input,
|
|
92
|
+
expect(ui8.concat(received)).to.deep.equal(
|
|
93
|
+
ui8.concat(input),
|
|
90
94
|
'Server did not receive the same bytes we sent'
|
|
91
95
|
)
|
|
92
96
|
})
|
|
@@ -102,6 +106,7 @@ describe('unidirectional streams', function () {
|
|
|
102
106
|
// server context - waits for the client to connect, opens a bidi stream, sends some data and reads the response
|
|
103
107
|
Promise.resolve().then(async () => {
|
|
104
108
|
const session = await getReaderValue(server.sessionStream(SERVER_PATH))
|
|
109
|
+
if (!session) throw new Error('no session')
|
|
105
110
|
const stream = await session.createUnidirectionalStream()
|
|
106
111
|
|
|
107
112
|
await writeStream(stream, input)
|
|
@@ -119,9 +124,9 @@ describe('unidirectional streams', function () {
|
|
|
119
124
|
await client.ready
|
|
120
125
|
|
|
121
126
|
const stream = await getReaderValue(client.incomingUnidirectionalStreams)
|
|
122
|
-
const received = await readStream(stream)
|
|
123
|
-
expect(received).to.deep.equal(
|
|
124
|
-
input,
|
|
127
|
+
const received = await readStream(stream, ui8.concat(input).length)
|
|
128
|
+
expect(ui8.concat(received)).to.deep.equal(
|
|
129
|
+
ui8.concat(input),
|
|
125
130
|
'Did not receive the same bytes we sent'
|
|
126
131
|
)
|
|
127
132
|
})
|
|
@@ -134,6 +139,7 @@ describe('unidirectional streams', function () {
|
|
|
134
139
|
|
|
135
140
|
Promise.resolve().then(async () => {
|
|
136
141
|
const session = await getReaderValue(server.sessionStream(SERVER_PATH))
|
|
142
|
+
if (!session) throw new Error('Got no session')
|
|
137
143
|
const stream = await getReaderValue(session.incomingUnidirectionalStreams)
|
|
138
144
|
|
|
139
145
|
serverStream.resolve(stream)
|
|
@@ -171,9 +177,12 @@ describe('unidirectional streams', function () {
|
|
|
171
177
|
|
|
172
178
|
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
173
179
|
|
|
174
|
-
const received = await readStream(
|
|
175
|
-
|
|
176
|
-
input
|
|
180
|
+
const received = await readStream(
|
|
181
|
+
await serverStream.promise,
|
|
182
|
+
ui8.concat(input).length
|
|
183
|
+
)
|
|
184
|
+
expect(ui8.concat(received)).to.deep.equal(
|
|
185
|
+
ui8.concat(input),
|
|
177
186
|
'Did not receive the same bytes we sent'
|
|
178
187
|
)
|
|
179
188
|
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// taken from chromium platfom impl
|
|
2
|
-
|
|
3
|
-
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
4
|
-
// Use of this source code is governed by a BSD-style license that can be
|
|
5
|
-
// found in the LICENSE file.
|
|
6
|
-
|
|
7
|
-
#ifndef NET_QUICHE_COMMON_PLATFORM_IMPL_QUICHE_FLAGS_IMPL_H_
|
|
8
|
-
#define NET_QUICHE_COMMON_PLATFORM_IMPL_QUICHE_FLAGS_IMPL_H_
|
|
9
|
-
|
|
10
|
-
#include "third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_flags_impl.h"
|
|
11
|
-
|
|
12
|
-
#endif // NET_QUICHE_COMMON_PLATFORM_IMPL_QUICHE_FLAGS_IMPL_H_
|
package/platform/poll.h
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// from envoy so LICENSE.envoy applies
|
|
2
|
-
#ifndef QUIC_TESTVALUE_IMPL_H
|
|
3
|
-
#define QUIC_TESTVALUE_IMPL_H
|
|
4
|
-
|
|
5
|
-
// NOLINT(namespace-envoy)
|
|
6
|
-
|
|
7
|
-
// This file is part of the QUICHE platform implementation, and is not to be
|
|
8
|
-
// consumed or referenced directly by other Envoy code. It serves purely as a
|
|
9
|
-
// porting layer for QUICHE.
|
|
10
|
-
|
|
11
|
-
#include "absl/strings/string_view.h"
|
|
12
|
-
|
|
13
|
-
namespace quic {
|
|
14
|
-
|
|
15
|
-
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
16
|
-
template <class T> void AdjustTestValueImpl(absl::string_view /*label*/, T* /*var*/) {}
|
|
17
|
-
|
|
18
|
-
} // namespace quic
|
|
19
|
-
#endif
|