github.com/gdamore/mangos@v1.4.0/socket.go (about)

     1  // Copyright 2015 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 mangos
    16  
    17  // Socket is the main access handle applications use to access the SP
    18  // system.  It is an abstraction of an application's "connection" to a
    19  // messaging topology.  Applications can have more than one Socket open
    20  // at a time.
    21  type Socket interface {
    22  	// Close closes the open Socket.  Further operations on the socket
    23  	// will return ErrClosed.
    24  	Close() error
    25  
    26  	// Send puts the message on the outbound send queue.  It blocks
    27  	// until the message can be queued, or the send deadline expires.
    28  	// If a queued message is later dropped for any reason,
    29  	// there will be no notification back to the application.
    30  	Send([]byte) error
    31  
    32  	// Recv receives a complete message.  The entire message is received.
    33  	Recv() ([]byte, error)
    34  
    35  	// SendMsg puts the message on the outbound send.  It works like Send,
    36  	// but allows the caller to supply message headers.  AGAIN, the Socket
    37  	// ASSUMES OWNERSHIP OF THE MESSAGE.
    38  	SendMsg(*Message) error
    39  
    40  	// RecvMsg receives a complete message, including the message header,
    41  	// which is useful for protocols in raw mode.
    42  	RecvMsg() (*Message, error)
    43  
    44  	// Dial connects a remote endpoint to the Socket.  The function
    45  	// returns immediately, and an asynchronous goroutine is started to
    46  	// establish and maintain the connection, reconnecting as needed.
    47  	// If the address is invalid, then an error is returned.
    48  	Dial(addr string) error
    49  
    50  	DialOptions(addr string, options map[string]interface{}) error
    51  
    52  	// NewDialer returns a Dialer object which can be used to get
    53  	// access to the underlying configuration for dialing.
    54  	NewDialer(addr string, options map[string]interface{}) (Dialer, error)
    55  
    56  	// Listen connects a local endpoint to the Socket.  Remote peers
    57  	// may connect (e.g. with Dial) and will each be "connected" to
    58  	// the Socket.  The accepter logic is run in a separate goroutine.
    59  	// The only error possible is if the address is invalid.
    60  	Listen(addr string) error
    61  
    62  	ListenOptions(addr string, options map[string]interface{}) error
    63  
    64  	NewListener(addr string, options map[string]interface{}) (Listener, error)
    65  
    66  	// GetOption is used to retrieve an option for a socket.
    67  	GetOption(name string) (interface{}, error)
    68  
    69  	// SetOption is used to set an option for a socket.
    70  	SetOption(name string, value interface{}) error
    71  
    72  	// Protocol is used to get the underlying Protocol.
    73  	GetProtocol() Protocol
    74  
    75  	// AddTransport adds a new Transport to the socket.  Transport specific
    76  	// options may have been configured on the Transport prior to this.
    77  	AddTransport(Transport)
    78  
    79  	// SetPortHook sets a PortHook function to be called when a Port is
    80  	// added or removed from this socket (connect/disconnect).  The previous
    81  	// hook is returned (nil if none.)
    82  	SetPortHook(PortHook) PortHook
    83  }