Skip to content

Commit

Permalink
fix: package ident
Browse files Browse the repository at this point in the history
Change-Id: I944469daa9fd259b64112eaf669a8a382c0051cf
  • Loading branch information
andeya committed Nov 14, 2019
1 parent 37335f7 commit 2687e16
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 104 deletions.
2 changes: 1 addition & 1 deletion examples/bench/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
erpc.SetGopool(1024*1024*100, time.Minute*10)

go func() {
log.Println(hterpc.ListenAndServe(*debugAddr, nil))
log.Println(http.ListenAndServe(*debugAddr, nil))
}()

conc, tn, err := msg.CheckArgs(*concurrency, *total)
Expand Down
2 changes: 1 addition & 1 deletion examples/bench/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
erpc.SetGopool(1024*1024*100, time.Minute*10)

go func() {
log.Println(hterpc.ListenAndServe(*debugAddr, nil))
log.Println(http.ListenAndServe(*debugAddr, nil))
}()

erpc.SetServiceMethodMapper(erpc.RPCServiceMethodMapper)
Expand Down
2 changes: 1 addition & 1 deletion mixer/evio/bench/tp_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
erpc.SetGopool(1024*1024*100, time.Minute*10)

go func() {
log.Println(hterpc.ListenAndServe(*debugAddr, nil))
log.Println(http.ListenAndServe(*debugAddr, nil))
}()

conc, tn, err := msg.CheckArgs(*concurrency, *total)
Expand Down
2 changes: 1 addition & 1 deletion mixer/evio/bench/tp_evio_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func main() {
erpc.SetGopool(1024*1024*100, time.Minute*10)

go func() {
log.Println(hterpc.ListenAndServe(*debugAddr, nil))
log.Println(http.ListenAndServe(*debugAddr, nil))
}()

erpc.SetServiceMethodMapper(erpc.RPCServiceMethodMapper)
Expand Down
2 changes: 1 addition & 1 deletion mixer/evio/evio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ $ go run examples/echo-server/main.go
These benchmarks were run on an ec2 c4.xlarge instance in single-threaded mode (GOMAXPROC=1) over Ipv4 localhost.
Check out [benchmarks](benchmarks) for more info.

<img src="benchmarks/out/echo.png" width="336" height="144" border="0" alt="echo benchmark"><img src="benchmarks/out/hterpc.png" width="336" height="144" border="0" alt="http benchmark"><img src="benchmarks/out/redis_pipeline_1.png" width="336" height="144" border="0" alt="redis 1 benchmark"><img src="benchmarks/out/redis_pipeline_8.png" width="336" height="144" border="0" alt="redis 8 benchmark">
<img src="benchmarks/out/echo.png" width="336" height="144" border="0" alt="echo benchmark"><img src="benchmarks/out/http.png" width="336" height="144" border="0" alt="http benchmark"><img src="benchmarks/out/redis_pipeline_1.png" width="336" height="144" border="0" alt="redis 1 benchmark"><img src="benchmarks/out/redis_pipeline_8.png" width="336" height="144" border="0" alt="redis 8 benchmark">


## Contact
Expand Down
4 changes: 2 additions & 2 deletions mixer/evio/evio/vendor/github.com/kavu/go_reuseport/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions mixer/evio/evio/vendor/github.com/kavu/go_reuseport/tcp_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mixer/websocket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func TestPbWebsocketTLS(t *testing.T) {

func TestCustomizedWebsocket(t *testing.T) {
srv := erpc.NewPeer(erpc.PeerConfig{})
hterpc.Handle("/ws", ws.NewJSONServeHandler(srv, nil))
go hterpc.ListenAndServe(":9092", nil)
http.Handle("/ws", ws.NewJSONServeHandler(srv, nil))
go http.ListenAndServe(":9092", nil)
srv.RouteCall(new(P))
time.Sleep(time.Second * 1)

Expand Down
26 changes: 13 additions & 13 deletions mixer/websocket/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ import (
type Server struct {
erpc.Peer
cfg erpc.PeerConfig
serveMux *hterpc.ServeMux
server *hterpc.Server
serveMux *http.ServeMux
server *http.Server
rootPath string
lis net.Listener
lisAddr net.Addr
handshake func(*ws.Config, *hterpc.Request) error
handshake func(*ws.Config, *http.Request) error
}

// NewServer creates a websocket server.
func NewServer(rootPath string, cfg erpc.PeerConfig, globalLeftPlugin ...erpc.Plugin) *Server {
p := erpc.NewPeer(cfg, globalLeftPlugin...)
serveMux := hterpc.NewServeMux()
serveMux := http.NewServeMux()
lisAddr := cfg.ListenAddr()
host, port, _ := net.SplitHostPort(lisAddr.String())
if port == "0" {
Expand All @@ -59,7 +59,7 @@ func NewServer(rootPath string, cfg erpc.PeerConfig, globalLeftPlugin ...erpc.Pl
serveMux: serveMux,
rootPath: fixRootPath(rootPath),
lisAddr: lisAddr,
server: &hterpc.Server{Addr: lisAddr.String(), Handler: serveMux},
server: &http.Server{Addr: lisAddr.String(), Handler: serveMux},
}
}

Expand Down Expand Up @@ -115,33 +115,33 @@ func (srv *Server) Close() error {
}

// SetHandshake sets customized handshake function.
func (srv *Server) SetHandshake(handshake func(*ws.Config, *hterpc.Request) error) {
func (srv *Server) SetHandshake(handshake func(*ws.Config, *http.Request) error) {
srv.handshake = handshake
}

// Handle registers the handler for the given rootPath.
// If a handler already exists for rootPath, Handle panics.
func (srv *Server) Handle(rootPath string, handler hterpc.Handler) {
func (srv *Server) Handle(rootPath string, handler http.Handler) {
srv.serveMux.Handle(rootPath, handler)
}

// HandleFunc registers the handler function for the given rootPath.
func (srv *Server) HandleFunc(rootPath string, handler func(hterpc.ResponseWriter, *hterpc.Request)) {
func (srv *Server) HandleFunc(rootPath string, handler func(http.ResponseWriter, *http.Request)) {
srv.serveMux.HandleFunc(rootPath, handler)
}

// NewJSONServeHandler creates a websocket json handler.
func NewJSONServeHandler(peer erpc.Peer, handshake func(*ws.Config, *hterpc.Request) error) hterpc.Handler {
func NewJSONServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error) http.Handler {
return NewServeHandler(peer, handshake, jsonSubProto.NewJSONSubProtoFunc())
}

// NewPbServeHandler creates a websocket protobuf handler.
func NewPbServeHandler(peer erpc.Peer, handshake func(*ws.Config, *hterpc.Request) error) hterpc.Handler {
func NewPbServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error) http.Handler {
return NewServeHandler(peer, handshake, pbSubProto.NewPbSubProtoFunc())
}

// NewServeHandler creates a websocket handler.
func NewServeHandler(peer erpc.Peer, handshake func(*ws.Config, *hterpc.Request) error, protoFunc ...erpc.ProtoFunc) hterpc.Handler {
func NewServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error, protoFunc ...erpc.ProtoFunc) http.Handler {
w := &serverHandler{
peer: peer,
Server: new(ws.Server),
Expand All @@ -154,15 +154,15 @@ func NewServeHandler(peer erpc.Peer, handshake func(*ws.Config, *hterpc.Request)
scheme = "wss"
}
if handshake != nil {
w.Server.Handshake = func(cfg *ws.Config, r *hterpc.Request) error {
w.Server.Handshake = func(cfg *ws.Config, r *http.Request) error {
cfg.Origin = &url.URL{
Host: r.RemoteAddr,
Scheme: scheme,
}
return handshake(cfg, r)
}
} else {
w.Server.Handshake = func(cfg *ws.Config, r *hterpc.Request) error {
w.Server.Handshake = func(cfg *ws.Config, r *http.Request) error {
cfg.Origin = &url.URL{
Host: r.RemoteAddr,
Scheme: scheme,
Expand Down
2 changes: 1 addition & 1 deletion mixer/websocket/websocket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewConfig(server, origin string) (config *Config, err error) {
if err != nil {
return
}
config.Header = hterpc.Header(make(map[string][]string))
config.Header = http.Header(make(map[string][]string))
return
}

Expand Down
26 changes: 13 additions & 13 deletions mixer/websocket/websocket/hybi.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (handler *hybiFrameHandler) WritePong(msg []byte) (n int, err error) {
}

// newHybiConn creates a new WebSocket connection speaking hybi draft protocol.
func newHybiConn(config *Config, buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *hterpc.Request) *Conn {
func newHybiConn(config *Config, buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *http.Request) *Conn {
if buf == nil {
br := bufio.NewReader(rwc)
bw := bufio.NewWriter(rwc)
Expand Down Expand Up @@ -437,7 +437,7 @@ func hybiClientHandshake(config *Config, br *bufio.Reader, bw *bufio.Writer) (er
return err
}

resp, err := hterpc.ReadResponse(br, &hterpc.Request{Method: "GET"})
resp, err := http.ReadResponse(br, &http.Request{Method: "GET"})
if err != nil {
return err
}
Expand Down Expand Up @@ -487,28 +487,28 @@ type hybiServerHandshaker struct {
accept []byte
}

func (c *hybiServerHandshaker) ReadHandshake(buf *bufio.Reader, req *hterpc.Request) (code int, err error) {
func (c *hybiServerHandshaker) ReadHandshake(buf *bufio.Reader, req *http.Request) (code int, err error) {
c.Version = ProtocolVersionHybi13
if req.Method != "GET" {
return hterpc.StatusMethodNotAllowed, ErrBadRequestMethod
return http.StatusMethodNotAllowed, ErrBadRequestMethod
}
// HTTP version can be safely ignored.

if strings.ToLower(req.Header.Get("Upgrade")) != "websocket" ||
!strings.Contains(strings.ToLower(req.Header.Get("Connection")), "upgrade") {
return hterpc.StatusBadRequest, ErrNotWebSocket
return http.StatusBadRequest, ErrNotWebSocket
}

key := req.Header.Get("Sec-Websocket-Key")
if key == "" {
return hterpc.StatusBadRequest, ErrChallengeResponse
return http.StatusBadRequest, ErrChallengeResponse
}
version := req.Header.Get("Sec-Websocket-Version")
switch version {
case "13":
c.Version = ProtocolVersionHybi13
default:
return hterpc.StatusBadRequest, ErrBadWebSocketVersion
return http.StatusBadRequest, ErrBadWebSocketVersion
}
var scheme string
if req.TLS != nil {
Expand All @@ -518,7 +518,7 @@ func (c *hybiServerHandshaker) ReadHandshake(buf *bufio.Reader, req *hterpc.Requ
}
c.Location, err = url.ParseRequestURI(scheme + "://" + req.Host + req.URL.RequestURI())
if err != nil {
return hterpc.StatusBadRequest, err
return http.StatusBadRequest, err
}
protocol := strings.TrimSpace(req.Header.Get("Sec-Websocket-Protocol"))
if protocol != "" {
Expand All @@ -529,14 +529,14 @@ func (c *hybiServerHandshaker) ReadHandshake(buf *bufio.Reader, req *hterpc.Requ
}
c.accept, err = getNonceAccept([]byte(key))
if err != nil {
return hterpc.StatusInternalServerError, err
return http.StatusInternalServerError, err
}
return hterpc.StatusSwitchingProtocols, nil
return http.StatusSwitchingProtocols, nil
}

// Origin parses the Origin header in req.
// If the Origin header is not set, it returns nil and nil.
func Origin(config *Config, req *hterpc.Request) (*url.URL, error) {
func Origin(config *Config, req *http.Request) (*url.URL, error) {
var origin string
switch config.Version {
case ProtocolVersionHybi13:
Expand Down Expand Up @@ -573,11 +573,11 @@ func (c *hybiServerHandshaker) AcceptHandshake(buf *bufio.Writer) (err error) {
return buf.Flush()
}

func (c *hybiServerHandshaker) NewServerConn(buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *hterpc.Request) *Conn {
func (c *hybiServerHandshaker) NewServerConn(buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *http.Request) *Conn {
return newHybiServerConn(c.Config, buf, rwc, request)
}

// newHybiServerConn returns a new WebSocket connection speaking hybi draft protocol.
func newHybiServerConn(config *Config, buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *hterpc.Request) *Conn {
func newHybiServerConn(config *Config, buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *http.Request) *Conn {
return newHybiConn(config, buf, rwc, request)
}
Loading

0 comments on commit 2687e16

Please sign in to comment.