From 6f4418750e67c72641a4373ab580b306b0c9304c Mon Sep 17 00:00:00 2001 From: "unai.avila" Date: Wed, 20 Aug 2014 10:55:54 +0200 Subject: Make Dial accept a timeout --- conn.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/conn.go b/conn.go index ed64b24..e771383 100644 --- a/conn.go +++ b/conn.go @@ -54,6 +54,18 @@ func Dial(network, addr string) (*Conn, error) { return conn, nil } +// DialTimeout connects to the given address on the given network using net.DialTimeout +// and then returns a new Conn for the connection. Acts like Dial but takes a timeout. +func DialTimeout(network, addr string, timeout time.Duration) (*Conn, error) { + c, err := net.DialTimeout(network, addr, timeout) + if err != nil { + return nil, NewError(ErrorNetwork, err) + } + conn := NewConn(c) + conn.start() + return conn, nil +} + // DialTLS connects to the given address on the given network using tls.Dial // and then returns a new Conn for the connection. func DialTLS(network, addr string, config *tls.Config) (*Conn, error) { -- cgit v1.2.3