Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Add openssl.DialTimeout(network, addr, timeout, ctx, flags) call #26

Merged
merged 1 commit into from
Jun 3, 2022
Merged
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
21 changes: 20 additions & 1 deletion net.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package openssl
import (
"errors"
"net"
"time"
)

type listener struct {
Expand Down Expand Up @@ -80,6 +81,18 @@ func Dial(network, addr string, ctx *Ctx, flags DialFlags) (*Conn, error) {
return DialSession(network, addr, ctx, flags, nil)
}

// DialTimeout acts like Dial but takes a timeout for network dial.
//
// The timeout includes only network dial. It does not include OpenSSL calls.
//
// See func Dial for a description of the network, addr, ctx and flags
// parameters.
func DialTimeout(network, addr string, timeout time.Duration, ctx *Ctx,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why omit the session param?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A reason is same as for regular Dial:

return DialSession(network, addr, ctx, flags, nil)

There is no need for this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. Thanks

flags DialFlags) (*Conn, error) {
d := net.Dialer {Timeout: timeout}
return dialSession(d, network, addr, ctx, flags, nil)
}

// DialSession will connect to network/address and then wrap the corresponding
// underlying connection with an OpenSSL client connection using context ctx.
// If flags includes InsecureSkipHostVerification, the server certificate's
Expand All @@ -95,7 +108,12 @@ func Dial(network, addr string, ctx *Ctx, flags DialFlags) (*Conn, error) {
// can be retrieved from the GetSession method on the Conn.
func DialSession(network, addr string, ctx *Ctx, flags DialFlags,
session []byte) (*Conn, error) {
var d net.Dialer
return dialSession(d, network, addr, ctx, flags, session);
}

func dialSession(d net.Dialer, network, addr string, ctx *Ctx, flags DialFlags,
session []byte) (*Conn, error) {
host, _, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
Expand All @@ -108,7 +126,8 @@ func DialSession(network, addr string, ctx *Ctx, flags DialFlags,
}
// TODO: use operating system default certificate chain?
}
c, err := net.Dial(network, addr)

c, err := d.Dial(network, addr)
if err != nil {
return nil, err
}
Expand Down