forked from jshiffer/go-xmpp
parent
da2b7586cd
commit
42ee290fc5
10
xmpp.go
10
xmpp.go
@ -76,7 +76,7 @@ func containsIgnoreCase(s, substr string) bool {
|
|||||||
return strings.Contains(s, substr)
|
return strings.Contains(s, substr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func connect(host, user, passwd string) (net.Conn, error) {
|
func connect(host, user, passwd string, timeout time.Duration) (net.Conn, error) {
|
||||||
addr := host
|
addr := host
|
||||||
|
|
||||||
if strings.TrimSpace(host) == "" {
|
if strings.TrimSpace(host) == "" {
|
||||||
@ -117,7 +117,7 @@ func connect(host, user, passwd string) (net.Conn, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := net.Dial("tcp", addr)
|
c, err := net.DialTimeout("tcp", addr, timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -153,6 +153,10 @@ type Options struct {
|
|||||||
// Password supplies the password to use for authentication with the remote server.
|
// Password supplies the password to use for authentication with the remote server.
|
||||||
Password string
|
Password string
|
||||||
|
|
||||||
|
// DialTimeout is the time limit for establishing a connection. A
|
||||||
|
// DialTimeout of zero means no timeout.
|
||||||
|
DialTimeout time.Duration
|
||||||
|
|
||||||
// Resource specifies an XMPP client resource, like "bot", instead of accepting one
|
// Resource specifies an XMPP client resource, like "bot", instead of accepting one
|
||||||
// from the server. Use "" to let the server generate one for your client.
|
// from the server. Use "" to let the server generate one for your client.
|
||||||
Resource string
|
Resource string
|
||||||
@ -221,7 +225,7 @@ func (o Options) NewClient() (*Client, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c, err := connect(host, o.User, o.Password)
|
c, err := connect(host, o.User, o.Password, o.DialTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user