Skip to content

Commit

Permalink
feat: added events for connection recv/send and stream readable/writable
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
tegefaulkes committed May 11, 2023
1 parent ff2e533 commit af0bfbc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/QUICConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ class QUICConnection extends EventTarget {
}
return;
}
this.dispatchEvent(new events.QUICConnectionRecvEvent());
// Here we can resolve our promises!
if (this.conn.isEstablished()) {
this.resolveEstablishedP();
Expand Down Expand Up @@ -482,6 +483,7 @@ class QUICConnection extends EventTarget {
);
}
quicStream.read();
quicStream.dispatchEvent(new events.QUICStreamReadableEvent());
}
for (const streamId of this.conn.writable() as Iterable<StreamId>) {
let quicStream = this.streamMap.get(streamId);
Expand All @@ -500,6 +502,7 @@ class QUICConnection extends EventTarget {
new events.QUICConnectionStreamEvent({ detail: quicStream }),
);
}
quicStream.dispatchEvent(new events.QUICStreamWritableEvent());
quicStream.write();
}
// Checking shortlist if streams have finished.
Expand Down Expand Up @@ -626,6 +629,7 @@ class QUICConnection extends EventTarget {
);
return;
}
this.dispatchEvent(new events.QUICConnectionSendEvent());
}
} finally {
this.logger.debug('SEND FINALLY');
Expand Down
2 changes: 1 addition & 1 deletion src/QUICStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class QUICStream

/**
* For `reasonToCode`, return 0 means "unknown reason"
* It is the catch all for codes.
* It is the catch-all for codes.
* So it is the default reason.
*
* It may receive any reason for cancellation.
Expand Down
39 changes: 27 additions & 12 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ class QUICConnectionStreamEvent extends Event {
}
}

class QUICConnectionSendEvent extends Event {
constructor(options?: EventInit) {
super('send', options);
}
}

class QUICConnectionRecvEvent extends Event {
constructor(options?: EventInit) {
super('recv', options);
}
}

class QUICConnectionDestroyEvent extends Event {
constructor(options?: EventInit) {
super('destroy', options);
Expand All @@ -89,18 +101,17 @@ class QUICConnectionErrorEvent extends Event {
}
}

// TODO: use these or remove them
// class QUICStreamReadableEvent extends Event {
// constructor(options?: EventInit) {
// super('readable', options);
// }
// }
//
// class QUICStreamWritableEvent extends Event {
// constructor(options?: EventInit) {
// super('writable', options);
// }
// }
class QUICStreamReadableEvent extends Event {
constructor(options?: EventInit) {
super('readable', options);
}
}

class QUICStreamWritableEvent extends Event {
constructor(options?: EventInit) {
super('writable', options);
}
}

class QUICStreamDestroyEvent extends Event {
constructor(options?: EventInit) {
Expand Down Expand Up @@ -133,8 +144,12 @@ export {
QUICServerStopEvent,
QUICServerErrorEvent,
QUICConnectionStreamEvent,
QUICConnectionSendEvent,
QUICConnectionRecvEvent,
QUICConnectionDestroyEvent,
QUICConnectionErrorEvent,
QUICStreamReadableEvent,
QUICStreamWritableEvent,
QUICStreamDestroyEvent,
QUICClientDestroyEvent,
QUICClientErrorEvent,
Expand Down

0 comments on commit af0bfbc

Please sign in to comment.