Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

bugfix: use same bufio.Reader for all requests in one connection. #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"strings"
)

func parseRequest(conn io.ReadCloser) (*Request, error) {
r := bufio.NewReader(conn)
func parseRequest(r *bufio.Reader) (*Request, error) {
// first line of redis request should be:
// *<number of arguments>CRLF
line, err := r.ReadString('\n')
Expand Down Expand Up @@ -43,7 +42,6 @@ func parseRequest(conn io.ReadCloser) (*Request, error) {
return &Request{
Name: strings.ToLower(string(firstArg)),
Args: args,
Body: conn,
}, nil
}

Expand All @@ -59,7 +57,6 @@ func parseRequest(conn io.ReadCloser) (*Request, error) {
return &Request{
Name: strings.ToLower(string(fields[0])),
Args: args,
Body: conn,
}, nil

}
Expand Down
6 changes: 1 addition & 5 deletions request.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package redis

import (
"io"
"strconv"
)
import "strconv"

type Request struct {
Name string
Args [][]byte
Host string
ClientChan chan struct{}
Body io.ReadCloser
}

func (r *Request) HasArgument(index int) bool {
Expand Down
4 changes: 3 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package redis

import (
"bufio"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -88,8 +89,9 @@ func (srv *Server) ServeClient(conn net.Conn) (err error) {
clientAddr = co.RemoteAddr().String()
}

br := bufio.NewReader(conn)
for {
request, err := parseRequest(conn)
request, err := parseRequest(br)
if err != nil {
return err
}
Expand Down