-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers.go
78 lines (59 loc) · 1.29 KB
/
helpers.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package zeroless
import (
"errors"
"strconv"
)
func checkPortInRange(port int) error {
if port < 1024 || port > 65535 {
return errors.New("Port " + strconv.Itoa(port) + " is invalid, choose one between 1024 and 65535")
}
return nil
}
func connectZmqSock(sock socket, ip string, port int) error {
if sock == nil {
panic("Sock is nil for connecting")
}
err := checkPortInRange(port)
if err != nil {
return err
}
endpoint := "tcp://" + ip + ":" + strconv.Itoa(port)
sock.Connect(endpoint)
return nil
}
func disconnectZmqSock(sock socket, ip string, port int) error {
if sock == nil {
panic("Sock is nil for disconnecting")
}
err := checkPortInRange(port)
if err != nil {
return err
}
endpoint := "tcp://" + ip + ":" + strconv.Itoa(port)
sock.Disconnect(endpoint)
return nil
}
func bindZmqSock(sock socket, port int) error {
if sock == nil {
panic("Sock is nil for binding")
}
err := checkPortInRange(port)
if err != nil {
return err
}
endpoint := "tcp://*:" + strconv.Itoa(port)
sock.Bind(endpoint)
return nil
}
func unbindZmqSock(sock socket, port int) error {
if sock == nil {
panic("Sock is nil for unbinding")
}
err := checkPortInRange(port)
if err != nil {
return err
}
endpoint := "tcp://*:" + strconv.Itoa(port)
sock.Unbind(endpoint)
return nil
}