forked from pothtonswer/discordmuffin
Prevent listen from reading from nulled out web socket.
This commit is contained in:
parent
bf5ca4d690
commit
d6d6c749ea
1 changed files with 3 additions and 3 deletions
6
wsapi.go
6
wsapi.go
|
@ -73,7 +73,7 @@ func (s *Session) Open() (err error) {
|
||||||
// Create listening outside of listen, as it needs to happen inside the mutex
|
// Create listening outside of listen, as it needs to happen inside the mutex
|
||||||
// lock.
|
// lock.
|
||||||
s.listening = make(chan interface{})
|
s.listening = make(chan interface{})
|
||||||
go s.listen(s.listening)
|
go s.listen(s.wsConn, s.listening)
|
||||||
|
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
|
|
||||||
|
@ -112,9 +112,9 @@ func (s *Session) Close() (err error) {
|
||||||
|
|
||||||
// listen polls the websocket connection for events, it will stop when
|
// listen polls the websocket connection for events, it will stop when
|
||||||
// the listening channel is closed, or an error occurs.
|
// the listening channel is closed, or an error occurs.
|
||||||
func (s *Session) listen(listening <-chan interface{}) {
|
func (s *Session) listen(wsConn *websocket.Conn, listening <-chan interface{}) {
|
||||||
for {
|
for {
|
||||||
messageType, message, err := s.wsConn.ReadMessage()
|
messageType, message, err := wsConn.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// There has been an error reading, Close() the websocket so that
|
// There has been an error reading, Close() the websocket so that
|
||||||
// OnDisconnect is fired.
|
// OnDisconnect is fired.
|
||||||
|
|
Loading…
Reference in a new issue