forked from go-zeromq/zmq4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
90 lines (75 loc) · 1.98 KB
/
options.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
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2018 The go-zeromq Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zmq4
import (
"log"
"time"
)
// Option configures some aspect of a ZeroMQ socket.
// (e.g. SocketIdentity, Security, ...)
type Option func(s *socket)
// WithID configures a ZeroMQ socket identity.
func WithID(id SocketIdentity) Option {
return func(s *socket) {
s.id = id
}
}
// WithSecurity configures a ZeroMQ socket to use the given security mechanism.
// If the security mechanims is nil, the NULL mechanism is used.
func WithSecurity(sec Security) Option {
return func(s *socket) {
s.sec = sec
}
}
// WithDialerRetry configures the time to wait before two failed attempts
// at dialing an endpoint.
func WithDialerRetry(retry time.Duration) Option {
return func(s *socket) {
s.retry = retry
}
}
// WithDialerTimeout sets the maximum amount of time a dial will wait
// for a connect to complete.
func WithDialerTimeout(timeout time.Duration) Option {
return func(s *socket) {
s.dialer.Timeout = timeout
}
}
// WithLogger sets a dedicated log.Logger for the socket.
func WithLogger(msg *log.Logger) Option {
return func(s *socket) {
s.log = msg
}
}
// WithDialerMaxRetries configures the maximum number of retries
// when dialing an endpoint (-1 means infinite retries).
func WithDialerMaxRetries(maxRetries int) Option {
return func(s *socket) {
s.maxRetries = maxRetries
}
}
// WithAutomaticReconnect allows to configure a socket to automatically
// reconnect on connection loss.
func WithAutomaticReconnect(automaticReconnect bool) Option {
return func(s *socket) {
s.autoReconnect = automaticReconnect
}
}
/*
// TODO(sbinet)
func WithIOThreads(threads int) Option {
return nil
}
func WithSendBufferSize(size int) Option {
return nil
}
func WithRecvBufferSize(size int) Option {
return nil
}
*/
const (
OptionSubscribe = "SUBSCRIBE"
OptionUnsubscribe = "UNSUBSCRIBE"
OptionHWM = "HWM"
)