go.nanomsg.org/mangos/v3@v3.4.3-0.20240217232803-46464076f1f5/protocol/pair/pair.go (about) 1 // Copyright 2018 The Mangos Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use file except in compliance with the License. 5 // You may obtain a copy of the license at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package pair implements the PAIR protocol. This protocol is a 1:1 16 // peering protocol. 17 package pair 18 19 import ( 20 "go.nanomsg.org/mangos/v3/protocol" 21 "go.nanomsg.org/mangos/v3/protocol/xpair" 22 ) 23 24 // Protocol identity information. 25 const ( 26 Self = protocol.ProtoPair 27 Peer = protocol.ProtoPair 28 SelfName = "pair" 29 PeerName = "pair" 30 ) 31 32 type socket struct { 33 protocol.Protocol 34 } 35 36 func (s *socket) GetOption(name string) (interface{}, error) { 37 switch name { 38 case protocol.OptionRaw: 39 return false, nil 40 } 41 return s.Protocol.GetOption(name) 42 } 43 44 // NewProtocol returns a new protocol implementation. 45 func NewProtocol() protocol.Protocol { 46 s := &socket{ 47 Protocol: xpair.NewProtocol(), 48 } 49 return s 50 } 51 52 // NewSocket allocates a raw Socket using the PAIR protocol. 53 func NewSocket() (protocol.Socket, error) { 54 return protocol.MakeSocket(NewProtocol()), nil 55 }