fix websocket crash

This commit is contained in:
rui.zheng 2016-01-11 11:31:23 +08:00
parent 3835ab437b
commit 59e7057fe9

9
ws.go
View File

@ -129,15 +129,18 @@ func (s *ws) handle(w http.ResponseWriter, r *http.Request) {
} }
func (s *ws) ListenAndServe() error { func (s *ws) ListenAndServe() error {
http.HandleFunc("/ws", s.handle) sm := http.NewServeMux()
return http.ListenAndServe(s.arg.Addr, nil) sm.HandleFunc("/ws", s.handle)
return http.ListenAndServe(s.arg.Addr, sm)
} }
func (s *ws) listenAndServeTLS() error { func (s *ws) listenAndServeTLS() error {
http.HandleFunc("/ws", s.handle) sm := http.NewServeMux()
sm.HandleFunc("/ws", s.handle)
server := &http.Server{ server := &http.Server{
Addr: s.arg.Addr, Addr: s.arg.Addr,
TLSConfig: &tls.Config{Certificates: []tls.Certificate{s.arg.Cert}}, TLSConfig: &tls.Config{Certificates: []tls.Certificate{s.arg.Cert}},
Handler: sm,
} }
return server.ListenAndServeTLS("", "") return server.ListenAndServeTLS("", "")
} }