network.sockets.local - Palamecia/mint GitHub Wiki

Module network.sockets.local

Description

load network.sockets.local

This module provides the Network.LocalSocket class which provides inter-process communication.

Packages

Enums

Network.LocalSocketOption

This enum describes the options of a local socket. The effective value of the option code can depend on the current system.

| Constant | Value | Description ||----------|-------|-------------|

Classes

Network.AsyncLocalSocket

This class provides an asynchronous socket communication mechanism that can be used to performe inter-process communication.

Inherits

Public members

Modifiers Member Description
class AcceptOperation Scheduler operation used to accept incoming connections asynchronously. Insta...
class ConnectOperation Scheduler operation used to establish a connection asynchronously. Instances ...
class ReadOperation Scheduler operation used to receive data asynchronously. Instances of this op...
class ReadSomeOperation Scheduler operation used to receive data asynchronously. Instances of this op...
class WriteOperation Scheduler operation used to send data asynchronously. Instances of this opera...
accept Waits asynchronously for the next incoming connection. The current coroutine ...
connect Attempts to establish a connection to the remote device identified by endpoint...
const listen Tells the socket to listen for incoming connections from endpoint. Returns true...
read
readSome Asynchronously receives at most count bytes of data from the peer. The operat...
write Asynchronously sends the data described by data to the peer. The data paramet...

Package members

Modifiers Member Description
final const getObjectData Returns the internal object data.
final const setObjectData Sets the internal object data to d_ptr.

Private members

Modifiers Member Description
@ const g_lib Global library handle.

Network.AsyncLocalSocket.AcceptOperation

Scheduler operation used to accept incoming connections asynchronously.

Instances of this operation are created by Network.AsyncLocalSocket.accept.

The operation asynchronously accepts a pending connection on the listening socket. The coroutine is suspended until the operating system completes the accept operation, at which point the coroutine resumes with the result.

When a connection is successfully accepted, the operation returns a new socket instance representing the client connection. The returned socket is already initialized and ready for communication.

An instance of Exception.SocketError is raised on error.

Inherits

Public members

Modifiers Member Description
override const check Checks for the operation completion. The operation succeed if a connection is...
override const get Returns the accepted socket or none if no connection was established.
const new Creates a new asynchronous operation to accept a pending connection on socket.

Protected members

Modifiers Member Description
override const setup Setup the operation by calling the underlying asynchronous accept function. R...

Private members

Modifiers Member Description
final client Internal accepted client connection socket.
@ const g_lib Global library handle.
final scheduler Internal scheduler.
final socket Internal socket.

Network.AsyncLocalSocket.ConnectOperation

Scheduler operation used to establish a connection asynchronously.

Instances of this operation are created by Network.AsyncLocalSocket.connect.

The operation asynchronously connects the socket. Once the connection operation completes, the coroutine resumes and the result of the operation is checked.

If the connection succeeds the socket enters the Network.Socket.State.Connected state.

If the connection fails the socket enters the Network.Socket.State.Error state and an instance of Exception.SocketError is raised.

Inherits

Public members

Modifiers Member Description
override const check Checks for the operation completion. The operation succeed if the underlying ...
override const get Returns true if the connection was correctly established; otherwise returns f...
const new Creates a new asynchronous operation to wait for socket connection.

Protected members

Modifiers Member Description
override const setup Setup the operation by calling the underlying asynchronous connect function. ...

Private members

Modifiers Member Description
final endpoint Internal endpoint.
@ const g_lib Global library handle.
final socket Internal socket.
final status Internal connection status.

Network.AsyncLocalSocket.ReadOperation

Scheduler operation used to receive data asynchronously.

Instances of this operation are created by Network.AsyncLocalSocket.read.

The operation asynchronously reads data from the socket and appends it to the internal receive buffer until the completion predicate returns true.

The completion predicate receives the current buffer and determines when the operation should finish. This allows callers to implement custom read conditions such as:

  • reading a fixed number of bytes
  • reading until a delimiter is encountered
  • reading until the buffer is non-empty

If the peer closes the connection before the completion condition is satisfied, the operation completes with the data accumulated so far.

An instance of Exception.SocketError is raised on error.

Inherits

Public members

Modifiers Member Description
override const check Checks for the operation completion. The operation succeed if data is availab...
override const get Returns the received data as an instance of Network.AsyncLocalSocket.ReadOper...
const new Creates a new asynchronous operation to read data from socket until the compl...

Protected members

Modifiers Member Description
override const setup Setup the operation by calling the underlying asynchronous read function. Ret...

Private members

Modifiers Member Description
final buffer Internal read buffer.
final completion Internal combination condition.
@ const g_lib Global library handle.
final socket Internal socket.

Network.AsyncLocalSocket.ReadSomeOperation

Scheduler operation used to receive data asynchronously.

Instances of this operation are created by Network.AsyncLocalSocket.readSome.

The operation asynchronously reads data from the socket and appends it to the internal receive buffer until enough data has been received.

If the peer closes the connection before enough data is received, the operation completes with the data accumulated so far.

An instance of Exception.SocketError is raised on error.

Inherits

Public members

Modifiers Member Description
override const check Checks for the operation completion. The operation succeed if data is availab...
override const get Returns the received data as an instance of Network.AsyncLocalSocket.ReadSome...
const new Creates a new asynchronous operation to read at most count bytes of data from ``...

Protected members

Modifiers Member Description
override const setup Setup the operation by calling the underlying asynchronous read function. Ret...

Private members

Modifiers Member Description
final buffer Internal read buffer.
final count Internal expected byte count.
@ const g_lib Global library handle.
final socket Internal socket.

Network.AsyncLocalSocket.WriteOperation

Scheduler operation used to send data asynchronously.

Instances of this operation are created by Network.AsyncLocalSocket.write.

The operation asynchronously sends the provided Serializer.DataStream using the socket.

Because network writes may be partial, the operation may perform multiple asynchronous writes until the entire buffer has been transmitted. The coroutine is suspended while the operation is in progress and resumes once the entire buffer has been sent.

Returns an iterator containing true and the amount of sent data in bytes if the data was successfully sent to the peer; otherwise returns false.

An instance of Exception.SocketError is raised on error.

Inherits

Public members

Modifiers Member Description
override const check Checks for the operation completion. The operation succeed if all the data in...
override const get Returns an iterator containing true and the amount of sent data in bytes if t...
const new Creates a new asynchronous operation to send the data provided by buffer to s...

Protected members

Modifiers Member Description
override const setup Setup the operation by calling the underlying asynchronous write function. Re...

Private members

Modifiers Member Description
final buffer Internal write buffer.
final count Internal sent byte counter.
@ const g_lib Global library handle.
final socket Internal socket.
final status Internal write status.

Network.LocalSocket

This class provides an awaitable socket communication mechanism that trigger an event when data become available on the read part and can be used to performe inter-process communication.

Inherits

Public members

Modifiers Member Description
const accept Returns a new end point initialized for the next waiting connection if any; o...
const asyncOn Returns a new instance of Network.LocalSocket.Network.AsyncLocalSocket initia...
override const close Closes the communication with the peer if the socket was in the Network.Local...
const connect Attempts to make a connection to the device identified by the endpoint parame...
override const getSocketOption Returns the value of the socket option described by option. The option parame...
const listen Tells the socket to listen for incoming connections from endpoint. Returns true...
const read Returns all available data received from the peer as an instance of Network.L...
const readSome Returns at most count bytes of data received from the peer as an instance of ``...
override const setNonBlocking Sets the non blocking mode of the socket to enabled. Returns true if the mode...
override const setSocketOption Sets the value of the socket option described by option to value. The option ...
const write Sends the data described by the data parameter to the peer. The data paramete...

Package members

Modifiers Member Description
final const getObjectData Returns the internal object data.
final const setObjectData Sets the internal object data to d_ptr.

Private members

Modifiers Member Description
final d_ptr Object data.
@ const g_lib Global library handle.

Descriptions

Network.AsyncLocalSocket.AcceptOperation.check

def (self, result)

Checks for the operation completion. The operation succeed if a connection is accepted. It fails on error.

Network.AsyncLocalSocket.AcceptOperation.client

none

Internal accepted client connection socket.

Network.AsyncLocalSocket.AcceptOperation.g_lib

lib ('libmint-network')

Global library handle.

Network.AsyncLocalSocket.AcceptOperation.get

def (self)

Returns the accepted socket or none if no connection was established.

Network.AsyncLocalSocket.AcceptOperation.new

def (self, socket)

Creates a new asynchronous operation to accept a pending connection on socket.

Network.AsyncLocalSocket.AcceptOperation.scheduler

null

Internal scheduler.

Network.AsyncLocalSocket.AcceptOperation.setup

def (self, scheduler)

Setup the operation by calling the underlying asynchronous accept function. Returns the internal object data of the operation. The operation will be completed using scheduler.

Network.AsyncLocalSocket.AcceptOperation.socket

null

Internal socket.

Network.AsyncLocalSocket.ConnectOperation.check

def (self, result)

Checks for the operation completion. The operation succeed if the underlying socket enter the Network.Socket.State.Connected state. It fails on error.

Network.AsyncLocalSocket.ConnectOperation.endpoint

null

Internal endpoint.

Network.AsyncLocalSocket.ConnectOperation.g_lib

lib ('libmint-network')

Global library handle.

Network.AsyncLocalSocket.ConnectOperation.get

def (self)

Returns true if the connection was correctly established; otherwise returns false.

Network.AsyncLocalSocket.ConnectOperation.new

def (self, socket, endpoint)

Creates a new asynchronous operation to wait for socket connection.

Network.AsyncLocalSocket.ConnectOperation.setup

def (self, scheduler)

Setup the operation by calling the underlying asynchronous connect function. Returns the internal object data of the operation. The operation will be completed using scheduler.

Network.AsyncLocalSocket.ConnectOperation.socket

null

Internal socket.

Network.AsyncLocalSocket.ConnectOperation.status

none

Internal connection status.

Network.AsyncLocalSocket.ReadOperation.buffer

null

Internal read buffer.

Network.AsyncLocalSocket.ReadOperation.check

def (self, result)

Checks for the operation completion. The operation succeed if data is available and the completion predicate returns true for the current read buffer. It fails on error.

Network.AsyncLocalSocket.ReadOperation.completion

null

Internal combination condition.

Network.AsyncLocalSocket.ReadOperation.g_lib

lib ('libmint-network')

Global library handle.

Network.AsyncLocalSocket.ReadOperation.get

def (self)

Returns the received data as an instance of Serializer.DataStream.

Network.AsyncLocalSocket.ReadOperation.new

def (self, socket, completion)

Creates a new asynchronous operation to read data from socket until the completion predicate returns true.

The completion parameter is a function that receives the current receive buffer and returns true when the operation should complete.

Network.AsyncLocalSocket.ReadOperation.setup

def (self, scheduler)

Setup the operation by calling the underlying asynchronous read function. Returns the internal object data of the operation. The operation will be completed using scheduler.

Network.AsyncLocalSocket.ReadOperation.socket

null

Internal socket.

Network.AsyncLocalSocket.ReadSomeOperation.buffer

null

Internal read buffer.

Network.AsyncLocalSocket.ReadSomeOperation.check

def (self, result)

Checks for the operation completion. The operation succeed if data is available and the completion predicate returns true for the current read buffer. It fails on error.

Network.AsyncLocalSocket.ReadSomeOperation.count

null

Internal expected byte count.

Network.AsyncLocalSocket.ReadSomeOperation.g_lib

lib ('libmint-network')

Global library handle.

Network.AsyncLocalSocket.ReadSomeOperation.get

def (self)

Returns the received data as an instance of Serializer.DataStream.

Network.AsyncLocalSocket.ReadSomeOperation.new

def (self, socket, count)

Creates a new asynchronous operation to read at most count bytes of data from socket.

Network.AsyncLocalSocket.ReadSomeOperation.setup

def (self, scheduler)

Setup the operation by calling the underlying asynchronous read function. Returns the internal object data of the operation. The operation will be completed using scheduler.

Network.AsyncLocalSocket.ReadSomeOperation.socket

null

Internal socket.

Network.AsyncLocalSocket.WriteOperation.buffer

null

Internal write buffer.

Network.AsyncLocalSocket.WriteOperation.check

def (self, result)

Checks for the operation completion. The operation succeed if all the data in the buffer is sent. It fails on error.

Network.AsyncLocalSocket.WriteOperation.count

0

Internal sent byte counter.

Network.AsyncLocalSocket.WriteOperation.g_lib

lib ('libmint-network')

Global library handle.

Network.AsyncLocalSocket.WriteOperation.get

def (self)

Returns an iterator containing true and the amount of sent data in bytes if the data was successfully sent to the peer; otherwise returns false.

Network.AsyncLocalSocket.WriteOperation.new

def (self, socket, buffer)

Creates a new asynchronous operation to send the data provided by buffer to socket.

Network.AsyncLocalSocket.WriteOperation.setup

def (self, scheduler)

Setup the operation by calling the underlying asynchronous write function. Returns the internal object data of the operation. The operation will be completed using scheduler.

Network.AsyncLocalSocket.WriteOperation.socket

null

Internal socket.

Network.AsyncLocalSocket.WriteOperation.status

false

Internal write status.

Network.AsyncLocalSocket.accept

def (self)

Waits asynchronously for the next incoming connection.

The current coroutine is suspended until a client connection becomes available or an error occurs.

Returns a new socket instance representing the accepted client connection.

The socket must be in the Network.Socket.State.Listening state.

The returned socket is already initialized and ready for I/O operations.

An instance of Exception.SocketError is raised if the accept operation fails.

Network.AsyncLocalSocket.connect

def (self, endpoint)

Attempts to establish a connection to the remote device identified by endpoint asynchronously.

This method suspends the current coroutine until the connection attempt either succeeds or fails.

Returns true if the connection was successfully established; otherwise returns false.

On success, the socket should enter the Network.Socket.State.Connected state.

On failure, the socket should enter the Network.Socket.State.Error state.

Network.AsyncLocalSocket.g_lib

lib ('libmint-network')

Global library handle.

Network.AsyncLocalSocket.getObjectData

def (self)

Returns the internal object data.

Network.AsyncLocalSocket.listen

def (self, endpoint)

Tells the socket to listen for incoming connections from endpoint. Returns true on success; otherwise returns false.

An instance of Exception.SocketError is raised on error.

Network.AsyncLocalSocket.read

def (buffer)

Network.AsyncLocalSocket.readSome

def (self, count)

Asynchronously receives at most count bytes of data from the peer.

The operation suspends the current coroutine until new data becomes available.

Returns the received data as an instance of Serializer.DataStream.

If the peer closes the connection before the completion condition is met, the returned buffer may contain fewer bytes than expected.

An instance of Exception.SocketError is raised on error.

Network.AsyncLocalSocket.setObjectData

def (self, d_ptr)

Sets the internal object data to d_ptr.

Network.AsyncLocalSocket.write

def (self, data)

Asynchronously sends the data described by data to the peer.

The data parameter must be an instance of Serializer.DataStream.

The operation suspends the current coroutine until all bytes have been written or an error occurs. Partial writes may occur internally and the operation will continue sending the remaining data until the buffer is empty.

Returns an iterator containing true and the amount of sent data in bytes if the data was successfully sent to the peer; otherwise returns false.

The socket must be in the Network.Socket.State.Connected state.

An instance of Exception.SocketError is raised on error.

Network.LocalSocket.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.

An instance of Exception.SocketError is raised on error.

Network.LocalSocket.asyncOn

def (self, scheduler)

Returns a new instance of Network.AsyncLocalSocket initialized with the current socket and the scheduler parameter.

Network.LocalSocket.close

def (self)

Closes the communication with the peer if the socket was in the Network.Socket.State.Connected state or stops listening if the socket was in the Network.Socket.State.Listening state.

On success, the socket enter the Network.Socket.State.Closed state.

[!NOTE] On Windows, closing the socket can discard the data that was not yet sent to the peer if the system does not support UNIX sockets. The application should ensure that all data is sent before closing the socket.

An instance of Exception.SocketError is raised on error.

Network.LocalSocket.connect

def (self, endpoint)

Attempts to make a connection to the device identified by the endpoint parameter. Returns true if connection succeed or if the connection request was successfully sent and is waiting for acknowledgment; otherwise returns false.

An instance of Exception.SocketError is raised on error.

Network.LocalSocket.d_ptr

null

Object data.

Network.LocalSocket.g_lib

lib ('libmint-network')

Global library handle.

Network.LocalSocket.getObjectData

def (self)

Returns the internal object data.

Network.LocalSocket.getSocketOption

def (self, % option)

Returns the value of the socket option described by option. The option parameter must be a value of the Network.LocalSocketOption enum.

An instance of Exception.SocketError is raised on error.

Network.LocalSocket.listen

def (self, endpoint)

Tells the socket to listen for incoming connections from endpoint. Returns true on success; otherwise returns false.

An instance of Exception.SocketError is raised on error.

Network.LocalSocket.read

def (self)

Returns all available data received from the peer as an instance of Serializer.DataStream or none if no data is available.

An instance of Exception.SocketError is raised on error.

Network.LocalSocket.readSome

def (self, count)

Returns at most count bytes of data received from the peer as an instance of Serializer.DataStream or none if no data is available.

An instance of Exception.SocketError is raised on error.

Network.LocalSocket.setNonBlocking

def (self, enabled)

Sets the non blocking mode of the socket to enabled. Returns true if the mode was successfully changed; otherwise returns false.

Network.LocalSocket.setObjectData

def (self, d_ptr)

Sets the internal object data to d_ptr.

Network.LocalSocket.setSocketOption

def (self, % option, value)

Sets the value of the socket option described by option to value. The option parameter must be a value of the Network.LocalSocketOption enum.

An instance of Exception.SocketError is raised on error.

Network.LocalSocket.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 iterator containing true and the amount of sent data in bytes if the data was successfully sent to the peer; otherwise returns false.

An instance of Exception.SocketError is raised on error.