This repository has been archived by the owner on Feb 3, 2020. It is now read-only.
/
protocol.go
92 lines (80 loc) · 2.92 KB
/
protocol.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
91
92
// Copyright 2018 The Mangos Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
// You may obtain a copy of the license at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Package protocol implements some common things protocol implementors
// need. Only protocol implementations should import this package.
package protocol
import (
"nanomsg.org/go/mangos/v2"
"nanomsg.org/go/mangos/v2/errors"
"nanomsg.org/go/mangos/v2/internal/core"
)
// Protocol numbers
const (
ProtoPair = mangos.ProtoPair
ProtoPub = mangos.ProtoPub
ProtoSub = mangos.ProtoSub
ProtoReq = mangos.ProtoReq
ProtoRep = mangos.ProtoRep
ProtoPush = mangos.ProtoPush
ProtoPull = mangos.ProtoPull
ProtoSurveyor = mangos.ProtoSurveyor
ProtoRespondent = mangos.ProtoRespondent
ProtoBus = mangos.ProtoBus
ProtoStar = mangos.ProtoStar // Experimental
)
// Pipe is a single connection -- provided by the transport layer.
type Pipe = mangos.ProtocolPipe
// Info describes a protocol and it's peer.
type Info = mangos.ProtocolInfo
// Context describes a protocol context.
type Context = mangos.ProtocolContext
// Protocol is the main ops vector for a protocol.
type Protocol = mangos.ProtocolBase
// Socket is the interface definition of a mangos.Socket.
// We need this for creating new ones.
type Socket = mangos.Socket
// Message is an alias for the common mangos.Message.
type Message = mangos.Message
// Borrow common error codes for convenience.
const (
ErrClosed = errors.ErrClosed
ErrSendTimeout = errors.ErrSendTimeout
ErrRecvTimeout = errors.ErrRecvTimeout
ErrBadValue = errors.ErrBadValue
ErrBadOption = errors.ErrBadOption
ErrProtoOp = errors.ErrProtoOp
ErrProtoState = errors.ErrProtoState
ErrCanceled = errors.ErrCanceled
)
// Common option definitions
// We have elided transport-specific options here.
const (
OptionRaw = mangos.OptionRaw
OptionRecvDeadline = mangos.OptionRecvDeadline
OptionSendDeadline = mangos.OptionSendDeadline
OptionRetryTime = mangos.OptionRetryTime
OptionSubscribe = mangos.OptionSubscribe
OptionUnsubscribe = mangos.OptionUnsubscribe
OptionSurveyTime = mangos.OptionSurveyTime
OptionWriteQLen = mangos.OptionWriteQLen
OptionReadQLen = mangos.OptionReadQLen
OptionLinger = mangos.OptionLinger // Remove?
OptionTTL = mangos.OptionTTL
OptionBestEffort = mangos.OptionBestEffort
)
// MakeSocket creates a Socket on top of a Protocol.
func MakeSocket(proto Protocol) Socket {
return core.MakeSocket(proto)
}