Skip to content

Commit

Permalink
Allow time.Duration or int for timeouts
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Rabot <[email protected]>
  • Loading branch information
sylr committed Feb 1, 2022
1 parent 94d7217 commit fda6c29
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
13 changes: 11 additions & 2 deletions dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package quickfix
import (
"fmt"
"net"
"time"

"github.com/quickfixgo/quickfix/config"
"golang.org/x/net/proxy"
Expand All @@ -11,8 +12,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
52 changes: 32 additions & 20 deletions session_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,47 +321,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 Expand Up @@ -404,7 +416,7 @@ func (f sessionFactory) buildHeartBtIntSettings(session *session, settings *Sess
return
}
}

if session.HeartBtIntOverride || mustProvide {
var heartBtInt int
if heartBtInt, err = settings.IntSetting(config.HeartBtInt); err != nil {
Expand Down

0 comments on commit fda6c29

Please sign in to comment.