From 1d80cf339293725be66c457a5caa0a136ec743c5 Mon Sep 17 00:00:00 2001 From: Anmol Sethi <hi@nhooyr.io> Date: Mon, 13 Apr 2020 22:45:59 -0400 Subject: [PATCH] Final doc fixes --- README.md | 2 +- accept.go | 6 ++---- conn_test.go | 1 - examples/chat/chat_test.go | 1 - examples/chat/main.go | 3 +-- examples/echo/main.go | 6 ------ 6 files changed, 4 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6096778..1f1ca46 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ go get nhooyr.io/websocket - First class [context.Context](https://blog.golang.org/context) support - Fully passes the WebSocket [autobahn-testsuite](https://github.com/crossbario/autobahn-testsuite) - Thorough tests with [90% coverage](https://coveralls.io/github/nhooyr/websocket) -- [Zero dependencies](https://pkg.go.dev/nhooyr.io/websocket?tab=imports) +- [Minimal dependencies](https://pkg.go.dev/nhooyr.io/websocket?tab=imports) - JSON and protobuf helpers in the [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) and [wspb](https://pkg.go.dev/nhooyr.io/websocket/wspb) subpackages - Zero alloc reads and writes - Concurrent writes diff --git a/accept.go b/accept.go index a583f23..47e20b5 100644 --- a/accept.go +++ b/accept.go @@ -134,7 +134,7 @@ func accept(w http.ResponseWriter, r *http.Request, opts *AcceptOptions) (_ *Con b, _ := brw.Reader.Peek(brw.Reader.Buffered()) brw.Reader.Reset(io.MultiReader(bytes.NewReader(b), netConn)) - c := newConn(connConfig{ + return newConn(connConfig{ subprotocol: w.Header().Get("Sec-WebSocket-Protocol"), rwc: netConn, client: false, @@ -143,9 +143,7 @@ func accept(w http.ResponseWriter, r *http.Request, opts *AcceptOptions) (_ *Con br: brw.Reader, bw: brw.Writer, - }) - - return c, nil + }), nil } func verifyClientRequest(w http.ResponseWriter, r *http.Request) (errCode int, _ error) { diff --git a/conn_test.go b/conn_test.go index 68dc837..451d093 100644 --- a/conn_test.go +++ b/conn_test.go @@ -271,7 +271,6 @@ func TestWasm(t *testing.T) { t.Skip("skipping on CI") } - // TODO grace s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { c, err := websocket.Accept(w, r, &websocket.AcceptOptions{ Subprotocols: []string{"echo"}, diff --git a/examples/chat/chat_test.go b/examples/chat/chat_test.go index 79523d2..eae1858 100644 --- a/examples/chat/chat_test.go +++ b/examples/chat/chat_test.go @@ -130,7 +130,6 @@ func setupTest(t *testing.T) (url string, closeFn func()) { cs.subscriberMessageBuffer = 4096 cs.publishLimiter.SetLimit(rate.Inf) - // TODO grace s := httptest.NewServer(cs) return s.URL, func() { s.Close() diff --git a/examples/chat/main.go b/examples/chat/main.go index cc2d01e..7f3cf6f 100644 --- a/examples/chat/main.go +++ b/examples/chat/main.go @@ -34,8 +34,7 @@ func run() error { log.Printf("listening on http://%v", l.Addr()) cs := newChatServer() - // TODO grace - s := http.Server{ + s := &http.Server{ Handler: cs, ReadTimeout: time.Second * 10, WriteTimeout: time.Second * 10, diff --git a/examples/echo/main.go b/examples/echo/main.go index db2d06c..f177175 100644 --- a/examples/echo/main.go +++ b/examples/echo/main.go @@ -16,11 +16,6 @@ import ( "nhooyr.io/websocket/wsjson" ) -// TODO IMPROVE CANCELLATION AND SHUTDOWN -// TODO on context cancel send websocket going away and fix the read timeout error to be dependant on context deadline reached. -// TODO this way you cancel your context and the right message automatically gets sent. Furthrmore, then u can just use a simple waitgroup to wait for connections. -// TODO grace is wrong as it doesn't wait for the individual goroutines. - // This example starts a WebSocket echo server, // dials the server and then sends 5 different messages // and prints out the server's responses. @@ -34,7 +29,6 @@ func main() { } defer l.Close() - // TODO grace s := &http.Server{ Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { err := echoServer(w, r) -- GitLab