forked from thinkgos/go-iecp5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
35 lines (30 loc) · 832 Bytes
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2020 thinkgos (thinkgo@aliyun.com). All rights reserved.
// Use of this source code is governed by a version 3 of the GNU General
// Public License, license that can be found in the LICENSE file.
package cs104
import (
"crypto/tls"
"errors"
"net"
"net/url"
"time"
)
// DefaultReconnectInterval defined default value
const DefaultReconnectInterval = 1 * time.Minute
type seqPending struct {
seq uint16
sendTime time.Time
}
func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration) (net.Conn, error) {
switch uri.Scheme {
case "tcp":
return net.DialTimeout("tcp", uri.Host, timeout)
case "ssl":
fallthrough
case "tls":
fallthrough
case "tcps":
return tls.DialWithDialer(&net.Dialer{Timeout: timeout}, "tcp", uri.Host, tlsc)
}
return nil, errors.New("Unknown protocol")
}