Skip to content

Commit

Permalink
webtransport: add a page about streams
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Apr 2, 2024
1 parent 194a481 commit d289599
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion content/docs/quic/streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ str, err := conn.OpenStreamSync(ctx)
Both `OpenStream` and `OpenStreamSync` return an error when the underlying QUIC connection is closed.


## Stream States
## Stream States {#states}

quic-go exposes three different stream abstractions: A `quic.SendStream` and a `quic.ReceiveStream`, for the two directions of unidirectional streams, and a `quic.Stream` for bidirectional streams.

Expand Down
2 changes: 1 addition & 1 deletion content/docs/webtransport/session.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: WebTransport Session
title: Session
toc: true
weight: 3
---
Expand Down
25 changes: 25 additions & 0 deletions content/docs/webtransport/streams.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: Streams
toc: true
weight: 4
---

A WebTransport stream functions similarly to a [QUIC Stream]({{< relref "../quic/streams.md" >}}). In particular, the stream state machines are exactly the same, as detailed in the [QUIC Stream documentation]({{< relref "../quic/streams.md#states" >}}). WebTransport supports both unidirectional and bidirectional streams.

The main difference between a QUIC stream and a WebTransport stream lies in the type of error codes used to reset the stream: QUIC allows error codes up to a 62-bit unsigned integer, while WebTransport error codes are limited to a 32-bit unsigned integer.


## Stream Errors

When a stream is reset (i.e. when `CancelRead` or `CancelWrite` are used), applications can communicate an error code to the peer. Subsequent calls to Read and Write may return an error that can be type-asserted as a `quic.StreamError`.

WebTransport itself does not interpret this value; instead, it is the responsibility of the application layer to assign specific meanings to different error codes.

Below is an example of how to type-assert an error as a `webtransport.StreamError`:

```go
var streamErr *webtransport.StreamError
if errors.As(err, &streamErr) {
errorCode := streamErr.ErrorCode
}
```

0 comments on commit d289599

Please sign in to comment.