-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathreqrep.go
49 lines (39 loc) · 1.25 KB
/
reqrep.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
// Go binding for nanomsg
package nanomsg
// #include <nanomsg/reqrep.h>
import "C"
import (
"time"
)
const (
REQ = Protocol(C.NN_REQ)
REP = Protocol(C.NN_REP)
)
type ReqSocket struct {
*Socket
}
// NewReqSocket creates a request socket used to implement the client
// application that sends requests and receives replies.
func NewReqSocket() (*ReqSocket, error) {
socket, err := NewSocket(AF_SP, REQ)
return &ReqSocket{socket}, err
}
// ResendInterval returns the resend interval. If reply is not received in
// specified amount of time, the request will be automatically resent. Default
// value is 1 minute.
func (req *ReqSocket) ResendInterval() (time.Duration, error) {
return req.Socket.SockOptDuration(C.NN_REQ, C.NN_REQ_RESEND_IVL, time.Millisecond)
}
// SetResendInterval sets the resend interval for requests.
func (req *ReqSocket) SetResendInterval(interval time.Duration) error {
return req.Socket.SetSockOptDuration(C.NN_REQ, C.NN_REQ_RESEND_IVL, time.Millisecond, interval)
}
type RepSocket struct {
*Socket
}
// NewRepSocket creates a reply socket used to implement the stateless worker
// that receives requests and sends replies.
func NewRepSocket() (*RepSocket, error) {
socket, err := NewSocket(AF_SP, REP)
return &RepSocket{socket}, err
}