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