mirror of https://github.com/fluffle/goirc
Alternative deadlock fix.
This commit is contained in:
parent
b4870bc685
commit
861f24a130
|
@ -288,13 +288,19 @@ func hasPort(s string) bool {
|
||||||
|
|
||||||
// goroutine to pass data from output channel to write()
|
// goroutine to pass data from output channel to write()
|
||||||
func (conn *Conn) send() {
|
func (conn *Conn) send() {
|
||||||
defer conn.wg.Done()
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case line := <-conn.out:
|
case line := <-conn.out:
|
||||||
conn.write(line)
|
if err := conn.write(line); err != nil {
|
||||||
|
logging.Error("irc.send(): %s", err.Error())
|
||||||
|
// We can't defer this, because shutdown() waits for it.
|
||||||
|
conn.wg.Done()
|
||||||
|
conn.shutdown()
|
||||||
|
return
|
||||||
|
}
|
||||||
case <-conn.die:
|
case <-conn.die:
|
||||||
// control channel closed, bail out
|
// control channel closed, bail out
|
||||||
|
conn.wg.Done()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,7 +363,7 @@ func (conn *Conn) runLoop() {
|
||||||
|
|
||||||
// Write a \r\n terminated line of output to the connected server,
|
// Write a \r\n terminated line of output to the connected server,
|
||||||
// using Hybrid's algorithm to rate limit if conn.cfg.Flood is false.
|
// using Hybrid's algorithm to rate limit if conn.cfg.Flood is false.
|
||||||
func (conn *Conn) write(line string) {
|
func (conn *Conn) write(line string) error {
|
||||||
if !conn.cfg.Flood {
|
if !conn.cfg.Flood {
|
||||||
if t := conn.rateLimit(len(line)); t != 0 {
|
if t := conn.rateLimit(len(line)); t != 0 {
|
||||||
// sleep for the current line's time value before sending it
|
// sleep for the current line's time value before sending it
|
||||||
|
@ -368,16 +374,13 @@ func (conn *Conn) write(line string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := conn.io.WriteString(line + "\r\n"); err != nil {
|
if _, err := conn.io.WriteString(line + "\r\n"); err != nil {
|
||||||
logging.Error("irc.send(): %s", err.Error())
|
return err
|
||||||
conn.shutdown()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if err := conn.io.Flush(); err != nil {
|
if err := conn.io.Flush(); err != nil {
|
||||||
logging.Error("irc.send(): %s", err.Error())
|
return err
|
||||||
conn.shutdown()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
logging.Debug("-> %s", line)
|
logging.Debug("-> %s", line)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement Hybrid's flood control algorithm to rate-limit outgoing lines.
|
// Implement Hybrid's flood control algorithm to rate-limit outgoing lines.
|
||||||
|
|
Loading…
Reference in New Issue