parent
d4de60a869
commit
29f2e93ab7
@ -244,6 +244,8 @@ func (dc *downstreamConn) readMessages(ch chan<- event) error {
|
||||
}
|
||||
|
||||
func (dc *downstreamConn) writeMessages() error {
|
||||
// TODO: any SendMessage call after the connection is closed will
|
||||
// either block or drop
|
||||
for {
|
||||
var err error
|
||||
var closed bool
|
||||
@ -252,6 +254,7 @@ func (dc *downstreamConn) writeMessages() error {
|
||||
if dc.srv.Debug {
|
||||
dc.logger.Printf("sent: %v", msg)
|
||||
}
|
||||
dc.net.SetWriteDeadline(time.Now().Add(writeTimeout))
|
||||
err = dc.irc.WriteMessage(msg)
|
||||
case <-dc.closed:
|
||||
closed = true
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
// TODO: make configurable
|
||||
var keepAlivePeriod = time.Minute
|
||||
var retryConnectMinDelay = time.Minute
|
||||
var writeTimeout = 10 * time.Second
|
||||
|
||||
func setKeepAlive(c net.Conn) error {
|
||||
tcpConn, ok := c.(*net.TCPConn)
|
||||
|
@ -111,6 +111,8 @@ func connectToUpstream(network *network) (*upstreamConn, error) {
|
||||
}
|
||||
|
||||
go func() {
|
||||
// TODO: any SendMessage call after the connection is closed will
|
||||
// either block or drop
|
||||
for {
|
||||
var closed bool
|
||||
select {
|
||||
@ -118,8 +120,10 @@ func connectToUpstream(network *network) (*upstreamConn, error) {
|
||||
if uc.srv.Debug {
|
||||
uc.logger.Printf("sent: %v", msg)
|
||||
}
|
||||
uc.net.SetWriteDeadline(time.Now().Add(writeTimeout))
|
||||
if err := uc.irc.WriteMessage(msg); err != nil {
|
||||
uc.logger.Printf("failed to write message: %v", err)
|
||||
closed = true
|
||||
}
|
||||
case <-uc.closed:
|
||||
closed = true
|
||||
|
Loading…
Reference in New Issue
Block a user