Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
sijms committed Nov 18, 2022
2 parents e653e71 + 19dd6e2 commit 3891bf2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions v2/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type Connection struct {
type OracleConnector struct {
drv *OracleDriver
connectString string
dialer network.DialerContext
}
type OracleDriver struct {
//m sync.Mutex
Expand Down Expand Up @@ -109,6 +110,7 @@ func (connector *OracleConnector) Connect(ctx context.Context) (driver.Conn, err
if err != nil {
return nil, err
}
conn.connOption.Dialer = connector.dialer
err = conn.OpenWithContext(ctx)
if err != nil {
return nil, err
Expand All @@ -120,6 +122,10 @@ func (connector *OracleConnector) Driver() driver.Driver {
return connector.drv
}

func (connector *OracleConnector) Dialer(dialer network.DialerContext) {
connector.dialer = dialer
}

// Open return a new open connection
func (drv *OracleDriver) Open(name string) (driver.Conn, error) {
conn, err := NewConnection(name)
Expand Down
7 changes: 7 additions & 0 deletions v2/network/connect_option.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package network

import (
"context"
"errors"
"fmt"
"net"
Expand Down Expand Up @@ -39,6 +40,11 @@ type DatabaseInfo struct {
AuthType int
connStr string
}

type DialerContext interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

type SessionInfo struct {
SSLVersion string
Timeout time.Duration
Expand All @@ -48,6 +54,7 @@ type SessionInfo struct {
Protocol string
SSL bool
SSLVerify bool
Dialer DialerContext
}
type AdvNegoSeviceInfo struct {
AuthService []string
Expand Down
10 changes: 7 additions & 3 deletions v2/network/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
"encoding/pem"
"errors"
"fmt"
"github.com/sijms/go-ora/v2/trace"
"net"
"reflect"
"strings"
"time"

"github.com/sijms/go-ora/v2/trace"

"github.com/sijms/go-ora/v2/converters"
)

Expand Down Expand Up @@ -279,8 +280,11 @@ func (session *Session) Connect(ctx context.Context) error {
var connected = false
var host *ServerAddr
var loop = true
dialer := net.Dialer{
Timeout: time.Second * session.Context.ConnOption.Timeout,
dialer := connOption.Dialer
if dialer == nil {
dialer = &net.Dialer{
Timeout: time.Second * session.Context.ConnOption.Timeout,
}
}
for loop {
host = connOption.GetActiveServer(false)
Expand Down

0 comments on commit 3891bf2

Please sign in to comment.