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

optimize reading performance #87

Open
lesismal opened this issue Jul 22, 2023 · 2 comments
Open

optimize reading performance #87

lesismal opened this issue Jul 22, 2023 · 2 comments

Comments

@lesismal
Copy link
Contributor

related:
gorilla/websocket#843

If the pr in gorilla is accepted, we can just add a similar configuration, else we need to change the implementation using NextReader.

@ghost
Copy link

ghost commented Jul 22, 2023

The code using NextReader will look something like this:

var buf bytes.Buffer
for {
	t, r, err := s.conn.NextReader()

	if err != nil {
		s.melody.errorHandler(s, err)
		break
	}

	buf.Reset()
	buf.ReadFrom(r)
	message := buf.Bytes()

	switch t {
	case websocket.TextMessage:
		s.melody.messageHandler(s, message)
	case websocket.BinaryMessage:
		s.melody.messageHandlerBinary(s, message)
	}
}

@lesismal
Copy link
Contributor Author

lesismal commented Jul 22, 2023

well, that's good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant