Skip to content

Commit

Permalink
add verbose config
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <zyl.skysniper@gmail.com>
  • Loading branch information
yilunzhang committed Jun 18, 2024
1 parent 6441b29 commit 80b230c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config struct {
CheckTimeoutInterval int32 // in millisecond
CheckBytesReadInterval int32 // in millisecond
SendBytesReadThreshold int32 // in millisecond
Verbose bool
}

var DefaultConfig = Config{
Expand All @@ -32,6 +33,7 @@ var DefaultConfig = Config{
CheckTimeoutInterval: 50,
CheckBytesReadInterval: 100,
SendBytesReadThreshold: 200,
Verbose: false,
}

func MergeConfig(conf *Config) (*Config, error) {
Expand Down
15 changes: 12 additions & 3 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
20 changes: 15 additions & 5 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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()
Expand Down

0 comments on commit 80b230c

Please sign in to comment.