network.poller - Palamecia/mint GitHub Wiki
Module network.poller
Description
load network.poller
This module provides the polling primitives used to monitor several network channels at once and notify them when their readiness state changes.
Packages
Enums
Network.PollEvent
This enum describe the events that can be watched on a specific channel.
| Constant | Value | Description ||----------|-------|-------------|
| Accept | 0x0004 | This event is set when a new connection is detected. |
| Close | 0x0010 | This event is set when the connection is closed by the peer. |
| Error | 0x0008 | This event is set when an error is detected. |
| Read | 0x0001 | This event is set when the endpoint has some waiting data to read. |
| Write | 0x0002 | This event is set when the data can be sent to the endpoint. |
Classes
Network.PollDescriptor
This class describe the polling state of a specific channel.
Public members
| Modifiers | Member | Description |
|---|---|---|
const |
getEvents | Returns the events activated on the channel as a mask of value from the Netwo... |
const |
getHandle | Returns the handle of the channel used by Network.PollDescriptor.Runtime.Sche... |
const |
getRequestedEvents | Returns the events requested on the channel as a mask of value from the Netwo... |
const |
new | Creates a new context for the channel given by channel. The channel object m... |
const |
poll | Waits until the activation of a requested event of the channel or until timeout... |
const |
setRequestedEvents | Sets requested events to events on the channel. The events parameter must be ... |
Private members
| Modifiers | Member | Description |
|---|---|---|
@ const |
g_lib | Global library handle. |
final |
handle | Internal channel handle. |
Network.Poller
This class provides mechanisms to wait for multiple network events.
An instance of Network.Poller watch a set of events. Severals instances of the class can be created to manage distinct sets.
The watched event objects must provide a getHandle method that return an instance of mint::handle_t.
Public members
| Modifiers | Member | Description |
|---|---|---|
const |
poll | Waits until the activation of requested events from the watched channels or u... |
const |
run | Runs a polling loop that calls Network.Poller.poll until no more channel is w... |
const |
unwatch | Removes the channel from the watcher. Returns true if channel is watched by t... |
const |
watch | Adds a channel to the watcher. The channel parameter can be either a Network.... |
Private members
| Modifiers | Member | Description |
|---|---|---|
final |
channels | Internal channels context. |
@ const |
g_lib | Global library handle. |
Descriptions
Network.PollDescriptor.g_lib
lib ('libmint-network')
Global library handle.
Network.PollDescriptor.getEvents
def (const self)
Returns the events activated on the channel as a mask of value from the Network.PollEvent enum.
Only events passed to setRequestedEvents can be activated.
Network.PollDescriptor.getHandle
def (const self)
Returns the handle of the channel used by Runtime.Scheduler.
Network.PollDescriptor.getRequestedEvents
def (const self)
Returns the events requested on the channel as a mask of value from the Network.PollEvent enum.
Network.PollDescriptor.handle
null
Internal channel handle.
Network.PollDescriptor.new
def (self, channel)
Creates a new context for the channel given by channel. The channel object must provide a getHandle
method returning the socket's handle as an instance of mint::handle_t.
Network.PollDescriptor.poll
def (self, timeout = 500)
Waits until the activation of a requested event of the channel or until timeout milliseconds if no event
become activated during this period.
Returns true if an event was activated; otherwise returns false.
After a call to this method, the value returned by getEvents is updated.
An instance of Exception.SocketError is raised on error.
Network.PollDescriptor.setRequestedEvents
def (self, events)
Sets requested events to events on the channel. The events
parameter must be a mask of values from the Network.PollEvent
enum.
Network.PollEvent.Accept
0x0004
This event is set when a new connection is detected.
Network.PollEvent.Close
0x0010
This event is set when the connection is closed by the peer.
Network.PollEvent.Error
0x0008
This event is set when an error is detected.
Network.PollEvent.Read
0x0001
This event is set when the endpoint has some waiting data to read.
Network.PollEvent.Write
0x0002
This event is set when the data can be sent to the endpoint.
Network.Poller.channels
{}
Internal channels context.
Network.Poller.g_lib
lib ('libmint-network')
Global library handle.
Network.Poller.poll
def (self, timeout = 500)
Waits until the activation of requested events from the watched channels or until timeout milliseconds if no
event become activated during this period.
For instances of Network.PollDescriptor, the events to watch are set using the Network.PollDescriptor.setRequestedEvents method. After a call to this function, the values returned by Network.PollDescriptor.getEvents are updated with the triggered events.
For any other objects, the watched events are selected using the Network.EventChannel.getEvents method. Any activated event on a channel will then be notified to the channel using the corresponding method:
Returns true if an event was activated; otherwise returns false.
An instance of Exception.SocketError is raised on error.
Network.Poller.run
def (self, timeout = 500)
Runs a polling loop that calls poll until no more channel is watched. The timeout parameter is
forwarded to the called method.
Network.Poller.unwatch
def (self, channel)
Removes the channel from the watcher. Returns true if channel is watched by the watcher; otherwise returns false.
Network.Poller.watch
def (self, channel)
Adds a channel to the watcher.
The channel parameter can be either a Network.PollDescriptor or an object with a Network.EventChannel
like interface.
Returns true if the channel is successfully watched; otherwise returns false.