Skip to content

Commit

Permalink
Merge pull request #477 from sylr/timeout-duration
Browse files Browse the repository at this point in the history
Allow time.Duration or int for timeouts
  • Loading branch information
ackleymi authored Oct 27, 2023
2 parents 2feb378 + 046163e commit a16527c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
13 changes: 11 additions & 2 deletions dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package quickfix
import (
"fmt"
"net"
"time"

"golang.org/x/net/proxy"

Expand All @@ -27,8 +28,16 @@ import (
func loadDialerConfig(settings *SessionSettings) (dialer proxy.Dialer, err error) {
stdDialer := &net.Dialer{}
if settings.HasSetting(config.SocketTimeout) {
if stdDialer.Timeout, err = settings.DurationSetting(config.SocketTimeout); err != nil {
return
timeout, err := settings.DurationSetting(config.SocketTimeout)
if err != nil {
timeoutInt, err := settings.IntSetting(config.SocketTimeout)
if err != nil {
return stdDialer, err
}

stdDialer.Timeout = time.Duration(timeoutInt) * time.Second
} else {
stdDialer.Timeout = timeout
}
}
dialer = stdDialer
Expand Down
50 changes: 31 additions & 19 deletions session_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,47 +361,59 @@ func (f sessionFactory) buildInitiatorSettings(session *session, settings *Sessi

session.ReconnectInterval = 30 * time.Second
if settings.HasSetting(config.ReconnectInterval) {

interval, err := settings.IntSetting(config.ReconnectInterval)
interval, err := settings.DurationSetting(config.ReconnectInterval)
if err != nil {
return err
intervalInt, err := settings.IntSetting(config.ReconnectInterval)
if err != nil {
return err
}

session.ReconnectInterval = time.Duration(intervalInt) * time.Second
} else {
session.ReconnectInterval = interval
}

if interval <= 0 {
if session.ReconnectInterval <= 0 {
return errors.New("ReconnectInterval must be greater than zero")
}

session.ReconnectInterval = time.Duration(interval) * time.Second
}

session.LogoutTimeout = 2 * time.Second
if settings.HasSetting(config.LogoutTimeout) {

timeout, err := settings.IntSetting(config.LogoutTimeout)
timeout, err := settings.DurationSetting(config.LogoutTimeout)
if err != nil {
return err
}
timeoutInt, err := settings.IntSetting(config.LogoutTimeout)
if err != nil {
return err
}

if timeout <= 0 {
return errors.New("LogoutTimeout must be greater than zero")
session.LogoutTimeout = time.Duration(timeoutInt) * time.Second
} else {
session.LogoutTimeout = timeout
}

session.LogoutTimeout = time.Duration(timeout) * time.Second
if session.LogoutTimeout <= 0 {
return errors.New("LogonTimeout must be greater than zero")
}
}

session.LogonTimeout = 10 * time.Second
if settings.HasSetting(config.LogonTimeout) {

timeout, err := settings.IntSetting(config.LogonTimeout)
timeout, err := settings.DurationSetting(config.LogonTimeout)
if err != nil {
return err
timeoutInt, err := settings.IntSetting(config.LogonTimeout)
if err != nil {
return err
}

session.LogonTimeout = time.Duration(timeoutInt) * time.Second
} else {
session.LogonTimeout = timeout
}

if timeout <= 0 {
if session.LogonTimeout <= 0 {
return errors.New("LogonTimeout must be greater than zero")
}

session.LogonTimeout = time.Duration(timeout) * time.Second
}

return f.configureSocketConnectAddress(session, settings)
Expand Down

0 comments on commit a16527c

Please sign in to comment.