nanomsg.org/go/mangos/v2@v2.0.9-0.20200203084354-8a092611e461/protocol/protocol.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  
    16  // Package protocol implements some common things protocol implementors
    17  // need.  Only protocol implementations should import this package.
    18  package protocol
    19  
    20  import (
    21  	"nanomsg.org/go/mangos/v2"
    22  	"nanomsg.org/go/mangos/v2/errors"
    23  	"nanomsg.org/go/mangos/v2/internal/core"
    24  )
    25  
    26  // Protocol numbers
    27  const (
    28  	ProtoPair       = mangos.ProtoPair
    29  	ProtoPub        = mangos.ProtoPub
    30  	ProtoSub        = mangos.ProtoSub
    31  	ProtoReq        = mangos.ProtoReq
    32  	ProtoRep        = mangos.ProtoRep
    33  	ProtoPush       = mangos.ProtoPush
    34  	ProtoPull       = mangos.ProtoPull
    35  	ProtoSurveyor   = mangos.ProtoSurveyor
    36  	ProtoRespondent = mangos.ProtoRespondent
    37  	ProtoBus        = mangos.ProtoBus
    38  	ProtoStar       = mangos.ProtoStar // Experimental
    39  )
    40  
    41  // Pipe is a single connection -- provided by the transport layer.
    42  type Pipe = mangos.ProtocolPipe
    43  
    44  // Info describes a protocol and it's peer.
    45  type Info = mangos.ProtocolInfo
    46  
    47  // Context describes a protocol context.
    48  type Context = mangos.ProtocolContext
    49  
    50  // Protocol is the main ops vector for a protocol.
    51  type Protocol = mangos.ProtocolBase
    52  
    53  // Socket is the interface definition of a mangos.Socket.
    54  // We need this for creating new ones.
    55  type Socket = mangos.Socket
    56  
    57  // Message is an alias for the common mangos.Message.
    58  type Message = mangos.Message
    59  
    60  // Borrow common error codes for convenience.
    61  const (
    62  	ErrClosed      = errors.ErrClosed
    63  	ErrSendTimeout = errors.ErrSendTimeout
    64  	ErrRecvTimeout = errors.ErrRecvTimeout
    65  	ErrBadValue    = errors.ErrBadValue
    66  	ErrBadOption   = errors.ErrBadOption
    67  	ErrProtoOp     = errors.ErrProtoOp
    68  	ErrProtoState  = errors.ErrProtoState
    69  	ErrCanceled    = errors.ErrCanceled
    70  )
    71  
    72  // Common option definitions
    73  // We have elided transport-specific options here.
    74  const (
    75  	OptionRaw          = mangos.OptionRaw
    76  	OptionRecvDeadline = mangos.OptionRecvDeadline
    77  	OptionSendDeadline = mangos.OptionSendDeadline
    78  	OptionRetryTime    = mangos.OptionRetryTime
    79  	OptionSubscribe    = mangos.OptionSubscribe
    80  	OptionUnsubscribe  = mangos.OptionUnsubscribe
    81  	OptionSurveyTime   = mangos.OptionSurveyTime
    82  	OptionWriteQLen    = mangos.OptionWriteQLen
    83  	OptionReadQLen     = mangos.OptionReadQLen
    84  	OptionLinger       = mangos.OptionLinger // Remove?
    85  	OptionTTL          = mangos.OptionTTL
    86  	OptionBestEffort   = mangos.OptionBestEffort
    87  )
    88  
    89  // MakeSocket creates a Socket on top of a Protocol.
    90  func MakeSocket(proto Protocol) Socket {
    91  	return core.MakeSocket(proto)
    92  }