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

I think writing to the output buffer wrong in examples (http server/ redis server) #58

Open
recoilme opened this issue Oct 18, 2019 · 1 comment

Comments

@recoilme
Copy link

Hello. I start from simple example how to work with evio:

	events.Data = func(ec evio.Conn, in []byte) (out []byte, action evio.Action) {
		if in == nil {
			fmt.Printf("wake from %s\n", ec.RemoteAddr())
			return nil, evio.Close
		}
		c := ec.Context().(*conn)
		data := c.is.Begin(in)
		for {
			leftover, response, err := mcproto(data, b52)
			if err != nil {
				if err != ErrClose {
					// bad thing happened
					println(err.Error())
				}
				action = evio.Close
				break
			} else if len(leftover) == len(data) {
				// request not ready, yet
				break
			}
			// handle the request
			out = response//next response may overwrite previous buffer
			data = leftover
		}
		c.is.End(data)
		return
	}

But out buffer will be overrided in case of piplined requests.
I think we must write to output - like this:

                responses := make([]byte, 0)
		for {
			leftover, response, err := mcproto(data, b52)

			// handle the response
			responses = append(responses, response...)
			//out = response// don't do like this
			data = leftover
		}
		out = responses// do like this
		c.is.End(data)

You may find test for that case - here: https://github.com/recoilme/b52/blob/master/main_test.go#L19

I am not sure what's going on internally - but spent two weeks, for finding that problem)
May be you have this kind of problem in rediconn+evio+pipelined, too

@recoilme
Copy link
Author

And special thanks for the great library! On the standard library, I could not even get close to the 2ms latency in my database https://github.com/recoilme/b52

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