nanomsg.org/go/mangos/v2@v2.0.9-0.20200203084354-8a092611e461/protocol/push/push.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 push implements the PUSH protocol, which is the write side of
    16  // the pipeline pattern.  (PULL is the reader.)
    17  package push
    18  
    19  import (
    20  	"nanomsg.org/go/mangos/v2/protocol"
    21  	"nanomsg.org/go/mangos/v2/protocol/xpush"
    22  )
    23  
    24  // Protocol identity information.
    25  const (
    26  	Self     = protocol.ProtoPush
    27  	Peer     = protocol.ProtoPull
    28  	SelfName = "push"
    29  	PeerName = "pull"
    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: xpush.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  }