Stop irc and websocket writer goroutines when the connection closes
This commit is contained in:
parent
e47cb5f0e4
commit
e55760a1a5
File diff suppressed because one or more lines are too long
@ -228,12 +228,15 @@ func (i *IRC) writef(format string, a ...interface{}) {
|
|||||||
func (i *IRC) send() {
|
func (i *IRC) send() {
|
||||||
i.ready.Wait()
|
i.ready.Wait()
|
||||||
for {
|
for {
|
||||||
i.conn.Write([]byte(<-i.out))
|
_, err := i.conn.Write([]byte(<-i.out))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IRC) recv() {
|
func (i *IRC) recv() {
|
||||||
defer i.conn.Close()
|
defer i.close()
|
||||||
for {
|
for {
|
||||||
line, err := i.reader.ReadString('\n')
|
line, err := i.reader.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -256,6 +259,12 @@ func (i *IRC) recv() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *IRC) close() {
|
||||||
|
i.conn.Close()
|
||||||
|
i.ready.Done()
|
||||||
|
close(i.out)
|
||||||
|
}
|
||||||
|
|
||||||
func parseMessage(line string) *Message {
|
func parseMessage(line string) *Message {
|
||||||
line = strings.Trim(line, "\r\n")
|
line = strings.Trim(line, "\r\n")
|
||||||
msg := Message{}
|
msg := Message{}
|
||||||
|
@ -67,6 +67,7 @@ func (s *Session) setWS(addr string, ws *websocket.Conn) {
|
|||||||
|
|
||||||
func (s *Session) deleteWS(addr string) {
|
func (s *Session) deleteWS(addr string) {
|
||||||
s.wsLock.Lock()
|
s.wsLock.Lock()
|
||||||
|
s.ws[addr].close()
|
||||||
delete(s.ws, addr)
|
delete(s.ws, addr)
|
||||||
s.wsLock.Unlock()
|
s.wsLock.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,13 @@ func NewWebSocket(ws *websocket.Conn) *WebSocket {
|
|||||||
|
|
||||||
func (w *WebSocket) write() {
|
func (w *WebSocket) write() {
|
||||||
for {
|
for {
|
||||||
w.conn.WriteMessage(websocket.TextMessage, <-w.Out)
|
err := w.conn.WriteMessage(websocket.TextMessage, <-w.Out)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WebSocket) close() {
|
||||||
|
close(w.Out)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user