Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow time.Duration or int for timeouts #477

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading