1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-03 07:56:42 -05:00

fix crash

This commit is contained in:
Shelikhoo 2016-08-14 20:40:59 +08:00
parent 49441a5050
commit 5e576e11bb
No known key found for this signature in database
GPG Key ID: 7791BDB0709ABD21

View File

@ -126,7 +126,9 @@ func (ws *wsconn) Write(b []byte) (n int, err error) {
} }
func (ws *wsconn) Close() error { func (ws *wsconn) Close() error {
ws.connClosing = true ws.connClosing = true
ws.wlock.Lock()
ws.wsc.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""), time.Now().Add((time.Second * 5))) ws.wsc.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""), time.Now().Add((time.Second * 5)))
ws.wlock.Unlock()
err := ws.wsc.Close() err := ws.wsc.Close()
return err return err
} }
@ -186,7 +188,9 @@ func (ws *wsconn) pingPong() {
go func() { go func() {
for !ws.connClosing { for !ws.connClosing {
ws.wlock.Lock()
ws.wsc.WriteMessage(websocket.PingMessage, nil) ws.wsc.WriteMessage(websocket.PingMessage, nil)
ws.wlock.Unlock()
tick := time.NewTicker(time.Second * 3) tick := time.NewTicker(time.Second * 3)
select { select {