-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathcmux.go
More file actions
37 lines (28 loc) · 724 Bytes
/
cmux.go
File metadata and controls
37 lines (28 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package grapiserver
import (
"net"
"github.com/soheilhy/cmux"
"google.golang.org/grpc/grpclog"
)
type cmuxServer struct {
mux cmux.CMux
lis net.Listener
}
func newCmuxServer(lis net.Listener) *cmuxServer {
return &cmuxServer{
mux: cmux.New(lis),
lis: lis,
}
}
// Serve implements Server.Serve
func (s *cmuxServer) Serve() {
grpclog.Info("mux is starting %s", s.lis.Addr())
err := s.mux.Serve()
grpclog.Infof("mux is closed: %v", err)
}
func (s *cmuxServer) GRPCListener() net.Listener {
return s.mux.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))
}
func (s *cmuxServer) HTTPListener() net.Listener {
return s.mux.Match(cmux.HTTP2(), cmux.HTTP1Fast())
}