network.endpoint - Palamecia/mint GitHub Wiki
Module
load network.endpoint
This module provides the Network.EndPoint class which provides an abstract interface to implement end point classes that manage communication with a peer using one specific protocol (layers 1 to 4 of the OSI model).
Packages
Enums
Network.EndPoint.IOStatus
This enum describes the status of an I/O operation.
Constant | Value | Description |
---|---|---|
IOClosed | 2 |
The I/O operation was performed on a closed device. |
IOError | 3 |
The I/O operation has failed. |
IOSuccess | 0 |
The I/O operation has succed. |
IOWouldBlock | 1 |
The I/O operation would block. |
Network.EndPoint.State
This enum describes the different states in which an end point can be.
Constant | Value | Description |
---|---|---|
Bound | 4 |
The end point is bound to an address and port. |
Closed | 7 |
The end point was closed. |
Closing | 6 |
The socket is about to close (data may still be waiting to be written). |
Connected | 3 |
A connection is established. |
Connecting | 2 |
The end point has started establishing a connection. |
Disconnected | 1 |
The end point is not connected. |
Error | 8 |
The end point entered an invalid state. |
Listening | 5 |
The end point is ready to receive connection requests. |
Unknown | 0 |
The end point is not initialized. |
Network.SocketOption
This enum describes the options of an endpoint's socket. The effetive value of the option code can depend on the current system.
Constant | Value | Description |
---|---|---|
BROADCAST | 0 |
Permit sending of broadcast datagrams (boolean). |
DEBUG | 1 |
Enable debug tracing (boolean). |
DONTROUTE | 2 |
Bypass routing table lookup (boolean). |
ERROR | 3 |
Get pending error and clear (Exception.SocketError, read only). |
KEEPALIVE | 4 |
Periodically test if connection still alive (boolean). |
LINGER | 5 |
Linger on close if data to send (Network.SocketLinger). |
OOBINLINE | 6 |
Leave received out-of-band data inline (boolean). |
RCVBUF | 7 |
Receive buffer size (number). |
RCVLOWAT | 9 |
Receive buffer low-water mark (number). |
RCVTIMEO | 11 |
Receive timeout (Network.SocketTime). |
REUSEADDR | 13 |
Allow local address reuse (boolean). |
REUSEPORT | 14 |
Allow local port reuse (boolean). |
SNDBUF | 8 |
Send buffer size (number). |
SNDLOWAT | 10 |
Send buffer low-water mark (number). |
SNDTIMEO | 12 |
Send timeout (Network.SocketTime). |
TYPE | 15 |
Get socket type (number, read only). |
USELOOPBACK | 16 |
Routing socket gets copy of what it sends (boolean). |
Classes
Network.EndPoint
This class provides an abstract interface to implement end point classes that manage communication with a peer using one specific protocol (layers 1 to 4 of the OSI model). It also implement the internal mechanisms of the interface.
Members
Modifiers | Member | Description |
---|---|---|
+ enum |
IOStatus | This enum describes the status of an I/O operation. |
+ enum |
State | This enum describes the different states in which an end point can be. |
+ const |
accept | Returns a new end point initialized for the next waiting connection if any; o... |
+ const |
bind | Tells the end point to listen for incoming messages. Returns true on succes... |
+ const |
close | Closes the communication with the peer if the end point was in the Network.En... |
+ const |
connect | Attempts to make a connection to the remote device. Returns true if connect... |
+ const |
finalizeClose | Finalize the close to the peer. Return true if the close succed; otherwise ... |
+ const |
finalizeConnection | Finalize the connection to the peer. Return true if the connection succed; ... |
- @ |
g_lib | Global library handle. |
+ const |
getSocket | Returns the end point's socket as a number or none if the end point has no ... |
+ const |
getSocketOption | Returns the value of the endpoint's socket option described by option . The ... |
+ const |
getState | Returns the current state of the end point as a value of Network.EndPoint.Sta... |
+ const |
isNonBlocking | Returns true if the end point performs I/O operations without blocking (i.e... |
+ const |
listen | Tells the end point to listen for incoming connections. Returns true on suc... |
+ const |
new | Creates a new end point. > This method initialize the internal end point's st... |
+ |
onState | This method can be rebinded to handle state change events. The state parame... |
+ const |
read | Returns all available data received from the peer as an instance of Serialize... |
+ const |
setNonBlocking | Sets the non blocking mode of the end point to enabled . Returns true if t... |
+ const |
setSocketOption | Sets the value of the endpoint's socket option described by option to val ... |
+ const |
setState | Sets the current state of the end point to state . The state parameter mus... |
- final % |
state | Internal end point's state. |
+ const |
write | Sends the data described by the data parameter to the peer. The data para... |
Network.SocketLinger
This class maintains information about a specific socket that specifies how that socket should behave when data is queued to be sent and Network.EndPoint.close is called on the socket.
Members
Modifiers | Member | Description |
---|---|---|
- final |
d_ptr | Object data. |
- @ |
g_lib | Global library handle. |
+ const |
getLingerTime | Specifies how long to remain open after closed to enable queued data to be se... |
+ const |
isEnabled | Returns true if enabled; otherwise returns false . This attribute specifie... |
+ const |
new | Creates a new linger object for the given data . The data parameter can be a... |
+ const |
setEnabled | Specifies whether a socket should remain open for a specified amount of time ... |
+ const |
setLingerTime | Sets the linger time in seconds. This attribute specifies how long to remain ... |
~ const |
to_linger | Returns the pointer to the internal struct linger instance. |
Network.SocketTime
This class is used to specify a time interval.
Members
Modifiers | Member | Description |
---|---|---|
- final |
d_ptr | Object data. |
- @ |
g_lib | Global library handle. |
+ const |
getMicroseconds | Returns the time interval, in microseconds. This value is used in combination... |
+ const |
getSeconds | Returns the time interval, in seconds. |
+ const |
new | Creates a new time interval object for the given data . The data parameter c... |
+ const |
setMicroseconds | Specifies the time interval in microseconds. This value is used in combinatio... |
+ const |
setSeconds | Specifies the time interval in seconds. |
~ const |
to_timeval | Returns the pointer to the internal struct timeval instance. |
Descriptions
Network.EndPoint.IOStatus.IOClosed
2
The I/O operation was performed on a closed device.
Network.EndPoint.IOStatus.IOError
3
The I/O operation has failed.
Network.EndPoint.IOStatus.IOSuccess
0
The I/O operation has succed.
Network.EndPoint.IOStatus.IOWouldBlock
1
The I/O operation would block.
Network.EndPoint.State.Bound
4
The end point is bound to an address and port.
Network.EndPoint.State.Closed
7
The end point was closed.
Network.EndPoint.State.Closing
6
The socket is about to close (data may still be waiting to be written).
Network.EndPoint.State.Connected
3
A connection is established.
Network.EndPoint.State.Connecting
2
The end point has started establishing a connection.
Network.EndPoint.State.Disconnected
1
The end point is not connected.
Network.EndPoint.State.Error
8
The end point entered an invalid state.
Network.EndPoint.State.Listening
5
The end point is ready to receive connection requests.
Network.EndPoint.State.Unknown
0
The end point is not initialized.
Network.EndPoint.accept
def (self)
Returns a new end point initialized for the next waiting connection
if any; otherwise returns none
. The waiting connection will then
be accepted and dequeued. The end point must be in the
Network.EndPoint.State.Listening state.
This method is an abstract method and should be implemented.
Network.EndPoint.bind
def (self)
Tells the end point to listen for incoming messages. Returns true
on success; otherwise returns false
. On success, the end point
should enter the Network.EndPoint.State.Bound state. On error, it
should enter the Network.EndPoint.State.Disconnected state.
This method is an abstract method and should be implemented.
Network.EndPoint.close
def (self)
Closes the communication with the peer if the end point was in the
Network.EndPoint.State.Connected state or stops listening if the
end point was in the Network.EndPoint.State.Listening state. Returns
true
if the socket was successfully closed; otherwise returns false
and the socket should then be closed later unsing finalizeClose.
On success, the end point should enter the Network.EndPoint.State.Closed
or Network.EndPoint.State.Closing state.
This method is an abstract method and should be implemented.
Network.EndPoint.connect
def (self)
Attempts to make a connection to the remote device. Returns true
if
connection succed or if the connection request was successfully sent
and is waiting for acknowledgment; otherwise returns false
. On
success, the end point should enter the Network.EndPoint.State.Connected
or Network.EndPoint.State.Connecting state. On error, it should
enter the Network.EndPoint.State.Disconnected state.
This method is an abstract method and should be implemented.
Network.EndPoint.finalizeClose
def (self)
Finalize the close to the peer. Return true
if the close succed;
otherwise returns false
. On success, the end point should
enter the Network.EndPoint.State.Closed state. On error, it should
enter the Network.EndPoint.State.Error state.
This method is an abstract method and should be implemented.
Network.EndPoint.finalizeConnection
def (self)
Finalize the connection to the peer. Return true
if the connection
succed; otherwise returns false
. On success, the end point should
enter the Network.EndPoint.State.Connected state. On error, it should
enter the Network.EndPoint.State.Disconnected state.
This method is an abstract method and should be implemented.
Network.EndPoint.g_lib
lib ('libmint-network')
Global library handle.
Network.EndPoint.getSocket
def (const self)
Returns the end point's socket as a number or none
if the end point
has no socket.
This method is an abstract method and should be implemented.
Network.EndPoint.getSocketOption
def (self, % option)
Returns the value of the endpoint's socket option described by
option
. The option
parameter must be a value of the
Network.SocketOption enum. If the option is not supported by the
system, none
is returned;
An instance of Exception.SocketError is raised on error.
Network.EndPoint.getState
def (const self)
Returns the current state of the end point as a value of Network.EndPoint.State.
Network.EndPoint.isNonBlocking
def (const self)
Returns true
if the end point performs I/O operations without blocking
(i.e. read or write returns immediately without waiting
for I/O completion); otherwise returns false
.
This method is an abstract method and should be implemented.
Network.EndPoint.listen
def (self)
Tells the end point to listen for incoming connections. Returns true
on success; otherwise returns false
. On success, the end point should
enter the Network.EndPoint.State.Listening state. On error, it should
enter the Network.EndPoint.State.Disconnected state.
This method is an abstract method and should be implemented.
Network.EndPoint.new
def (self)
Creates a new end point.
This method initialize the internal end point's state and must be called in the implementation class constructor.
Network.EndPoint.onState
def (self, % state)
This method can be rebinded to handle state change events. The state
parameter is the state that will be applied to the end point. The
previous state can still be accessed with getState until the
end of the method.
[!WARNING] Calling setState in this method can result in an infinite loop.
Network.EndPoint.read
def (self)
Returns all available data received from the peer as an instance of
Serializer.DataStream or none
if no data is available. The end
point must be in the Network.EndPoint.State.Connected state.
This method is an abstract method and should be implemented.
Network.EndPoint.setNonBlocking
def (self, enabled)
Sets the non blocking mode of the end point to enabled
. Returns
true
if the mode was successfully changed; otherwise returns
false
.
This method is an abstract method and should be implemented.
Network.EndPoint.setSocketOption
def (self, % option, value)
Sets the value of the endpoint's socket option described by option
to value
. The option
parameter must be a value of the
Network.SocketOption enum. Returns true
if the option is supported
by the system; otherwise returns false
.
An instance of Exception.SocketError is raised on error.
Network.EndPoint.setState
def (self, % state)
Sets the current state of the end point to state
. The state
parameter
must be a value of the Network.EndPoint.State enum.
Network.EndPoint.state
null
Internal end point's state.
Network.EndPoint.write
def (self, data)
Sends the data described by the data
parameter to the peer. The
data
parameter must be an instance of Serializer.DataStream.
Returns an iteraror containing true
and the amount of sent data in
bytes if the data was successfully sent to the peer; otherwise returns
false
. The end point must be in the Network.EndPoint.State.Connected
state.
This method is an abstract method and should be implemented.
Network.SocketLinger.d_ptr
null
Object data.
Network.SocketLinger.g_lib
lib ('libmint-network')
Global library handle.
Network.SocketLinger.getLingerTime
def (const self)
Specifies how long to remain open after closed to enable queued data to be sent. This attribute is only applicable if enabled.
Network.SocketLinger.isEnabled
def (const self)
Returns true
if enabled; otherwise returns false
. This attribute
specifies whether a socket should remain open for a specified amount
of time after closed to enable queued data to be sent.
Network.SocketLinger.new
def (self, data)
Creates a new linger object for the given data
. The data parameter
can be an instance of Network.SocketLinger, in this case the object
is returned as the new instance, or an instance of the linger
C
struct. The parameter can also provide a toSocketLinger
method that
will be used to create the object.
def (self, const enable, const linger_time)
Creates a new linger object. The enable
parameter must be a boolean
value used to specifies whether a socket should remain open for a
specified amount of time after closed to enable queued data to be sent.
The linger_time
parameter must be a number used, if enabled, to sets
the linger time in seconds. This value specifies how long to remain open
after a closesocket function call to enable queued data to be sent.
Network.SocketLinger.setEnabled
def (self, const enabled)
Specifies whether a socket should remain open for a specified amount of time after closed to enable queued data to be sent.
Network.SocketLinger.setLingerTime
def (self, const linger_time)
Sets the linger time in seconds. This attribute specifies how long to remain open after closed to enable queued data to be sent. It is only applicable if enabled.
Network.SocketLinger.to_linger
def (const self)
Returns the pointer to the internal struct linger
instance.
Network.SocketOption.BROADCAST
0
Permit sending of broadcast datagrams (boolean).
Network.SocketOption.DEBUG
1
Enable debug tracing (boolean).
Network.SocketOption.DONTROUTE
2
Bypass routing table lookup (boolean).
Network.SocketOption.ERROR
3
Get pending error and clear (Exception.SocketError, read only).
Network.SocketOption.KEEPALIVE
4
Periodically test if connection still alive (boolean).
Network.SocketOption.LINGER
5
Linger on close if data to send (Network.SocketLinger).
Network.SocketOption.OOBINLINE
6
Leave received out-of-band data inline (boolean).
Network.SocketOption.RCVBUF
7
Receive buffer size (number).
Network.SocketOption.RCVLOWAT
9
Receive buffer low-water mark (number).
Network.SocketOption.RCVTIMEO
11
Receive timeout (Network.SocketTime).
Network.SocketOption.REUSEADDR
13
Allow local address reuse (boolean).
Network.SocketOption.REUSEPORT
14
Allow local port reuse (boolean).
Network.SocketOption.SNDBUF
8
Send buffer size (number).
Network.SocketOption.SNDLOWAT
10
Send buffer low-water mark (number).
Network.SocketOption.SNDTIMEO
12
Send timeout (Network.SocketTime).
Network.SocketOption.TYPE
15
Get socket type (number, read only).
Network.SocketOption.USELOOPBACK
16
Routing socket gets copy of what it sends (boolean).
Network.SocketTime.d_ptr
null
Object data.
Network.SocketTime.g_lib
lib ('libmint-network')
Global library handle.
Network.SocketTime.getMicroseconds
def (const self)
Returns the time interval, in microseconds. This value is used in combination with the value of getSeconds to represent time interval values that are not a multiple of seconds.
Network.SocketTime.getSeconds
def (const self)
Returns the time interval, in seconds.
Network.SocketTime.new
def (self, data)
Creates a new time interval object for the given data
. The data
parameter can be an instance of Network.SocketTime, in this case
the object is returned as the new instance, or an instance of the
timeval
C struct. The parameter can also provide a toTime
method
that will be used to create the object.
def (self, const sec, const usec)
Creates a new time interval object. The sec
parameter must be a number
used to specifies the time interval in seconds. The usec
parameter
must be a number used to specifies the time interval, in microseconds.
This parameter is used in combination with the sec
parameter to
represent time interval values that are not a multiple of seconds.
Network.SocketTime.setMicroseconds
def (self, const usec)
Specifies the time interval in microseconds. This value is used in combination with the value passed to setSeconds to represent time interval values that are not a multiple of seconds.
Network.SocketTime.setSeconds
def (self, const sec)
Specifies the time interval in seconds.
Network.SocketTime.to_timeval
def (const self)
Returns the pointer to the internal struct timeval
instance.