github.com/gdamore/mangos@v1.4.0/port.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  // Port represents the high level interface to a low level communications
    18  // channel.  There is one of these associated with a given TCP connection,
    19  // for example.  This interface is intended for application use.
    20  //
    21  // Note that applicatons cannot send or receive data on a Port directly.
    22  type Port interface {
    23  
    24  	// Address returns the address (URL form) associated with the port.
    25  	// This matches the string passed to Dial() or Listen().
    26  	Address() string
    27  
    28  	// GetProp returns an arbitrary property.  The details will vary
    29  	// for different transport types.
    30  	GetProp(name string) (interface{}, error)
    31  
    32  	// IsOpen determines whether this is open or not.
    33  	IsOpen() bool
    34  
    35  	// Close closes the Conn.  This does a disconnect, or something similar.
    36  	// Note that if a dialer is present and active, it will redial.
    37  	Close() error
    38  
    39  	// IsServer returns true if the connection is from a server (Listen).
    40  	IsServer() bool
    41  
    42  	// IsClient returns true if the connection is from a client (Dial).
    43  	IsClient() bool
    44  
    45  	// LocalProtocol returns the local protocol number.
    46  	LocalProtocol() uint16
    47  
    48  	// RemoteProtocol returns the remote protocol number.
    49  	RemoteProtocol() uint16
    50  
    51  	// Dialer returns the dialer for this Port, or nil if a server.
    52  	Dialer() Dialer
    53  
    54  	// Listener returns the listener for this Port, or nil if a client.
    55  	Listener() Listener
    56  }
    57  
    58  // PortAction determines whether the action on a Port is addition or removal.
    59  type PortAction int
    60  
    61  // PortAction values.
    62  const (
    63  	PortActionAdd = iota
    64  	PortActionRemove
    65  )
    66  
    67  // PortHook is a function that is called when a port is added or removed to or
    68  // from a Socket.  In the case of PortActionAdd, the function may return false
    69  // to indicate that the port should not be added.
    70  type PortHook func(PortAction, Port) bool