C# Class CrossroadsIO.Devices.Device

Forwards messages received by a front-end socket to a back-end socket, from which they are then sent.
The base implementation of Device is not threadsafe. Do not construct a device with sockets that were created in separate threads or separate contexts.
Inheritance: IDevice
Show file Open project: jgoz/crossroads-net Class Usage Examples

Protected Properties

Property Type Description
BackendSocket Socket
FrontendSocket Socket

Public Methods

Method Description
Close ( ) : void

Stop the device and safely terminate the underlying sockets.

Dispose ( ) : void

Releases all resources used by the current instance, including the frontend and backend sockets.

Initialize ( ) : void

Initializes the frontend and backend sockets. Called automatically when starting the device. If called multiple times, will only execute once.

Join ( System.TimeSpan timeout ) : bool

Blocks the calling thread until the device terminates or the specified time elapses.

Join ( ) : void

Blocks the calling thread until the device terminates.

Start ( ) : void

Start the device in the current thread.

Stop ( ) : void

Stop the device in such a way that it can be restarted.

Protected Methods

Method Description
BackendHandler ( SocketEventArgs args ) : void

Invoked when a message has been received by the backend socket.

Device ( Socket frontendSocket, Socket backendSocket, DeviceMode mode ) : System

Initializes a new instance of the Device class.

Dispose ( bool disposing ) : void

Stops the device and releases the underlying sockets. Optionally disposes of managed resources.

FrontendHandler ( SocketEventArgs args ) : void

Invoked when a message has been received by the frontend socket.

Run ( ) : void

Start the device in the current thread. Should be used by implementations of the DeviceRunner.Start method.

Initializes the sockets prior to starting the device with Initialize.

Private Methods

Method Description
EnsureNotDisposed ( ) : void

Method Details

BackendHandler() protected abstract method

Invoked when a message has been received by the backend socket.
protected abstract BackendHandler ( SocketEventArgs args ) : void
args SocketEventArgs A object containing the poll event args.
return void

Close() public method

Stop the device and safely terminate the underlying sockets.
public Close ( ) : void
return void

Device() protected method

Initializes a new instance of the Device class.
protected Device ( Socket frontendSocket, Socket backendSocket, DeviceMode mode ) : System
frontendSocket Socket /// A that will pass incoming messages to . ///
backendSocket Socket /// A that will receive messages from (and optionally send replies to) . ///
mode DeviceMode The for the current device.
return System

Dispose() public method

Releases all resources used by the current instance, including the frontend and backend sockets.
public Dispose ( ) : void
return void

Dispose() protected method

Stops the device and releases the underlying sockets. Optionally disposes of managed resources.
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; false to release only unmanaged resources.
return void

FrontendHandler() protected abstract method

Invoked when a message has been received by the frontend socket.
protected abstract FrontendHandler ( SocketEventArgs args ) : void
args SocketEventArgs A object containing the poll event args.
return void

Initialize() public method

Initializes the frontend and backend sockets. Called automatically when starting the device. If called multiple times, will only execute once.
public Initialize ( ) : void
return void

Join() public method

Blocks the calling thread until the device terminates or the specified time elapses.
public Join ( System.TimeSpan timeout ) : bool
timeout System.TimeSpan /// A set to the amount of time to wait for the device to terminate. ///
return bool

Join() public method

Blocks the calling thread until the device terminates.
public Join ( ) : void
return void

Run() protected method

Start the device in the current thread. Should be used by implementations of the DeviceRunner.Start method.
Initializes the sockets prior to starting the device with Initialize.
protected Run ( ) : void
return void

Start() public method

Start the device in the current thread.
The has already been disposed.
public Start ( ) : void
return void

Stop() public method

Stop the device in such a way that it can be restarted.
public Stop ( ) : void
return void

Property Details

BackendSocket protected property

The backend socket that will normally receive messages from (and possibly send replies to) FrontendSocket.
protected Socket BackendSocket
return Socket

FrontendSocket protected property

The frontend socket that will normally pass messages to BackendSocket.
protected Socket FrontendSocket
return Socket