Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to error on any data messages from the peer #98

Closed
nhooyr opened this issue Jun 23, 2019 · 5 comments
Closed

Add function to error on any data messages from the peer #98

nhooyr opened this issue Jun 23, 2019 · 5 comments

Comments

@nhooyr
Copy link
Contributor

nhooyr commented Jun 23, 2019

https://github.com/nhooyr/websocket/blob/31492255de53f0499a7255b5c4f45b345cb3ec7b/example_test.go#L77

@ammario suggested I add a function for that. I agree but I don't know what to name it.

@ammario
Copy link
Member

ammario commented Jun 23, 2019

CloseRead

@nhooyr
Copy link
Contributor Author

nhooyr commented Jun 23, 2019

That makes a lot of sense yup. Will add.

@nhooyr
Copy link
Contributor Author

nhooyr commented Jun 23, 2019

Nvm, if you call CloseRead, how will you cancel your context when the connection dies?

@nhooyr
Copy link
Contributor Author

nhooyr commented Jun 23, 2019

The function I'm thinking of is just

func SomeName(ctx) {
    c.Reader(ctx)
    c.Close(websocket.StatusPolicyViolation, "server doesn't accept data messages")
}

So you'd use it like

go func() {
    defer cancel()
    c.SomeName()
}()

@nhooyr
Copy link
Contributor Author

nhooyr commented Jun 23, 2019

I guess you could have:

func (c *Conn) CloseRead(ctx context.Context) (context.Context) {
    // spawn goroutine in example and return a context that will be cancelled when the goroutine returns
}

That seems reasonable. 🤔

@nhooyr nhooyr closed this as completed in 559c169 Jun 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants