diff --git a/config.go b/config.go index b70a1cb..b12da3c 100644 --- a/config.go +++ b/config.go @@ -16,6 +16,7 @@ type Config struct { CheckTimeoutInterval int32 // in millisecond CheckBytesReadInterval int32 // in millisecond SendBytesReadThreshold int32 // in millisecond + Verbose bool } var DefaultConfig = Config{ @@ -32,6 +33,7 @@ var DefaultConfig = Config{ CheckTimeoutInterval: 50, CheckBytesReadInterval: 100, SendBytesReadThreshold: 200, + Verbose: false, } func MergeConfig(conf *Config) (*Config, error) { diff --git a/connection.go b/connection.go index 0cee326..36f6e43 100644 --- a/connection.go +++ b/connection.go @@ -159,7 +159,9 @@ func (conn *Connection) tx() error { if err == ErrConnClosed { return err } - log.Println(err) + if conn.session.config.Verbose { + log.Println(err) + } // reduce window size conn.Lock() @@ -234,17 +236,24 @@ func (conn *Connection) sendAck() error { BytesRead: conn.session.GetBytesRead(), }) if err != nil { - log.Println(err) + if conn.session.config.Verbose { + log.Println(err) + } time.Sleep(time.Second) continue } err = conn.session.sendWith(conn.localClientID, conn.remoteClientID, buf, conn.retransmissionTimeout) if err != nil { + if conn.session.IsClosed() { + return ErrSessionClosed + } if err == ErrConnClosed { return err } - log.Println(err) + if conn.session.config.Verbose { + log.Println(err) + } time.Sleep(time.Second) continue } diff --git a/session.go b/session.go index 31fa23a..721d4c6 100644 --- a/session.go +++ b/session.go @@ -342,7 +342,9 @@ func (session *Session) startFlush() error { if session.context.Err() != nil { return session.context.Err() } - log.Println(err) + if session.config.Verbose { + log.Println(err) + } continue } } @@ -370,7 +372,9 @@ func (session *Session) startCheckBytesRead() error { BytesRead: bytesRead, }) if err != nil { - log.Println(err) + if session.config.Verbose { + log.Println(err) + } time.Sleep(time.Second) continue } @@ -379,7 +383,9 @@ func (session *Session) startCheckBytesRead() error { for _, connection := range session.connections { err = session.sendWith(connection.localClientID, connection.remoteClientID, buf, connection.RetransmissionTimeout()) if err != nil { - log.Println(err) + if session.config.Verbose { + log.Println(err) + } time.Sleep(time.Second) continue } @@ -889,7 +895,9 @@ func (session *Session) Close() error { if session.config.Linger != 0 { err := session.flushSendBuffer() if err != nil { - log.Println(err) + if session.config.Verbose { + log.Println(err) + } } func() { @@ -911,7 +919,9 @@ func (session *Session) Close() error { err := session.sendClosePacket() if err != nil { - log.Println(err) + if session.config.Verbose { + log.Println(err) + } } session.cancel()