nanomsg.org/go/mangos/v2@v2.0.9-0.20200203084354-8a092611e461/protocol/pull/pull.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 pull implements the PULL protocol, which is the read side of
    16  // the pipeline pattern.  (PUSH is the reader.)
    17  package pull
    18  
    19  import (
    20  	"nanomsg.org/go/mangos/v2/protocol"
    21  	"nanomsg.org/go/mangos/v2/protocol/xpull"
    22  )
    23  
    24  type socket struct {
    25  	protocol.Protocol
    26  }
    27  
    28  // Protocol identity information.
    29  const (
    30  	Self     = protocol.ProtoPull
    31  	Peer     = protocol.ProtoPush
    32  	SelfName = "pull"
    33  	PeerName = "push"
    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: xpull.NewProtocol(),
    48  	}
    49  	return s
    50  }
    51  
    52  // NewSocket allocates a raw Socket using the PULL protocol.
    53  func NewSocket() (protocol.Socket, error) {
    54  	return protocol.MakeSocket(NewProtocol()), nil
    55  }