Package sick_ldmrs :: Module xport :: Class XPort
[frames] | no frames]

Class XPort

source code

object --+
         |
        XPort

Class representation of a socket transport thread.

Simplification wrapper around socket.socket and related objects. The send and recv methods will wait for all requested data and/or provide a filtered exception (something good, bad, or ugly happened).

Instance Methods
 
__init__(self, host, port)
XPort constructor, connect to requested peer.
source code
str
recv(self, length)
Wait for data from the network peer.
source code
 
send(self, cmd)
Send a data message to the network peer.
source code
 
shutdown(self)
Call socket.shutdown to pop out of any blocking send/recv
source code
 
close(self)
close the xport socket
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, host, port)
(Constructor)

source code 

XPort constructor, connect to requested peer.

Connect to requested network peer or raise reason why not.

Parameters:
  • host (str) - hostname to connect to. can be name or IPv4 dot notation.
  • port (int) - network port to connect to
Raises:
  • FatalExcetpion - Host/port does not exist or is unreachable.
  • TimeoutException - Network is reachable but timeout on connect. Likely host is not yet ready.
  • InfoRestartException - Non-fatal network problem, able to re-try.
  • ErrorRestartException - More serious network problem, possibly can re-try.
Overrides: object.__init__

recv(self, length)

source code 

Wait for data from the network peer.

Wait until all requested data from the network peer has arrived.

Parameters:
  • length (int) - how much data is requested
Returns: str
data from network peer
Raises:
  • TimeoutException - no data has arrived in the timeout period
  • InfoRestartException - remote peer has closed the socket, the data request can not be fulfilled but able to reconnect to peer.
  • NextMsgException - signal interruption, current data request can not be fulfilled but new request can be issued
  • ErrorRestartException - network problem reported and data request can not be fulfilled. should reconnect to peer.

send(self, cmd)

source code 

Send a data message to the network peer.

Send all requested message data.

Parameters:
  • cmd (str) - data to send
Raises:
  • TimeoutException - data could not be sent during the timeout period, likely the peer has gone down
  • InfoRestartException - peer has closed connection or local shutdown signal caught. either way current send can not be fulfilled.
  • ErrorRestartException - network problem reported and data send can not be fulfilled. should reconnect to peer.