Skip to content

Commit 480d0eb

Browse files
committed
Fixes from @albrow's Wasm review
1 parent ef5a88d commit 480d0eb

File tree

7 files changed

+23
-14
lines changed

7 files changed

+23
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ go get nhooyr.io/websocket
2323
- JSON and ProtoBuf helpers in the [wsjson](https://godoc.org/nhooyr.io/websocket/wsjson) and [wspb](https://godoc.org/nhooyr.io/websocket/wspb) subpackages
2424
- Highly optimized by default
2525
- Concurrent writes out of the box
26-
- [Complete WASM](https://godoc.org/nhooyr.io/websocket#hdr-WASM) support
26+
- [Complete Wasm](https://godoc.org/nhooyr.io/websocket#hdr-Wasm) support
2727

2828
## Roadmap
2929

@@ -130,7 +130,7 @@ The ping API is also nicer. gorilla/websocket requires registering a pong handle
130130
which results in awkward control flow. With nhooyr/websocket you use the Ping method on the Conn
131131
that sends a ping and also waits for the pong.
132132

133-
Additionally, nhooyr.io/websocket can compile to [WASM](https://godoc.org/nhooyr.io/websocket#hdr-WASM) for the browser.
133+
Additionally, nhooyr.io/websocket can compile to [Wasm](https://godoc.org/nhooyr.io/websocket#hdr-Wasm) for the browser.
134134

135135
In terms of performance, the differences mostly depend on your application code. nhooyr/websocket
136136
reuses message buffers out of the box if you use the wsjson and wspb subpackages.

assert_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package websocket_test
22

33
import (
44
"context"
5-
"encoding/hex"
65
"fmt"
76
"math/rand"
87
"reflect"
8+
"strings"
99

1010
"github.com/google/go-cmp/cmp"
1111

@@ -99,7 +99,16 @@ func randBytes(n int) []byte {
9999
}
100100

101101
func randString(n int) string {
102-
return hex.EncodeToString(randBytes(n))[:n]
102+
s := strings.ToValidUTF8(string(randBytes(n)), "_")
103+
if len(s) > n {
104+
return s[:n]
105+
}
106+
if len(s) < n {
107+
// Pad with =
108+
extra := n - len(s)
109+
return s + strings.Repeat("=", extra)
110+
}
111+
return s
103112
}
104113

105114
func assertEcho(ctx context.Context, c *websocket.Conn, typ websocket.MessageType, n int) error {

conn_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This file contains *Conn symbols relevant to both
2-
// WASM and non WASM builds.
2+
// Wasm and non Wasm builds.
33

44
package websocket
55

doc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
// Use the errors.As function new in Go 1.13 to check for websocket.CloseError.
1919
// See the CloseError example.
2020
//
21-
// WASM
21+
// Wasm
2222
//
23-
// The client side fully supports compiling to WASM.
23+
// The client side fully supports compiling to Wasm.
2424
// It wraps the WebSocket browser API.
2525
//
2626
// See https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
2727
//
28-
// Thus the unsupported features (not compiled in) for WASM are:
28+
// Thus the unsupported features (not compiled in) for Wasm are:
2929
//
3030
// - Accept and AcceptOptions
3131
// - Conn.Ping

frame.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ const (
213213

214214
StatusNoStatusRcvd
215215

216-
// This StatusCode is only exported for use with WASM.
217-
// In non WASM Go, the returned error will indicate whether the connection was closed or not or what happened.
216+
// This StatusCode is only exported for use with Wasm.
217+
// In non Wasm Go, the returned error will indicate whether the connection was closed or not or what happened.
218218
StatusAbnormalClosure
219219

220220
StatusInvalidFramePayloadData
@@ -226,8 +226,8 @@ const (
226226
StatusTryAgainLater
227227
StatusBadGateway
228228

229-
// This StatusCode is only exported for use with WASM.
230-
// In non WASM Go, the returned error will indicate whether there was a TLS handshake failure.
229+
// This StatusCode is only exported for use with Wasm.
230+
// In non Wasm Go, the returned error will indicate whether there was a TLS handshake failure.
231231
StatusTLSHandshake
232232
)
233233

File renamed without changes.

websocket_js_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ func TestConn(t *testing.T) {
3636
t.Fatal(err)
3737
}
3838

39-
err = assertJSONEcho(ctx, c, 16)
39+
err = assertJSONEcho(ctx, c, 1024)
4040
if err != nil {
4141
t.Fatal(err)
4242
}
4343

44-
err = assertEcho(ctx, c, websocket.MessageBinary, 16)
44+
err = assertEcho(ctx, c, websocket.MessageBinary, 1024)
4545
if err != nil {
4646
t.Fatal(err)
4747
}

0 commit comments

Comments
 (0)