Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 559c169

Browse files
committedJun 23, 2019
Add CloseRead
Closes #98
1 parent 956dbd8 commit 559c169

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
 

‎websocket.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,16 @@ func (c *Conn) reader(ctx context.Context) (MessageType, io.Reader, error) {
388388
return MessageType(h.opcode), r, nil
389389
}
390390

391+
func (c *Conn) CloseRead(ctx context.Context) context.Context {
392+
ctx, cancel := context.WithCancel(ctx)
393+
go func() {
394+
defer cancel()
395+
c.Reader(ctx)
396+
c.Close(StatusPolicyViolation, "unexpected data message")
397+
}()
398+
return ctx
399+
}
400+
391401
// messageReader enables reading a data frame from the WebSocket connection.
392402
type messageReader struct {
393403
c *Conn

0 commit comments

Comments
 (0)
Please sign in to comment.