C# Class NetMQ.Core.SocketBase

Inheritance: NetMQ.Core.Own, IPollEvents, Pipe.IPipeEvents
Show file Open project: NetMQ/NetMQ3-x Class Usage Examples

Private Properties

Property Type Description
AddEndpoint void
AttachPipe void
CheckContextTerminated void
CheckDestroy void
CheckProtocol void
Create SocketBase
DecodeAddress void
ExtractFlags void
GetTypeString string
MonitorEvent void
ProcessCommands void
StartReaping void
StopMonitor void

Public Methods

Method Description
Bind ( [ addr ) : void

Bind this socket to the given address.

The supported protocols are "inproc", "ipc", "tcp", "pgm", and "epgm". If the protocol is either "pgm" or "epgm", then this socket must be of type Pub, Sub, XPub, or XSub. If the protocol is "inproc", you cannot bind to the same address more than once.

BindRandomPort ( [ addr ) : int

Bind the specified TCP address to an available port, assigned by the operating system.

CheckDisposed ( ) : void

Throw ObjectDisposedException if this socket is already disposed.

Close ( ) : void

Close this socket. Mark it as disposed, and send ownership of it to the reaper thread to attend to the rest of it's shutdown process.

Connect ( [ addr ) : void

Connect this socket to the given address.

The supported protocols are "inproc", "ipc", "tcp", "pgm", and "epgm". If the protocol is either "pgm" or "epgm", then this socket must be of type Pub, Sub, XPub, or XSub.

Destroy ( ) : void

Destroy this socket - which means to stop monitoring the queue for messages. This simply calls StopMonitor, and then verifies that the destroyed-flag is set.

EventAcceptFailed ( [ addr, ErrorCode errno ) : void
EventAccepted ( [ addr, [ ch ) : void
EventBindFailed ( [ addr, ErrorCode errno ) : void
EventCloseFailed ( [ addr, ErrorCode errno ) : void
EventClosed ( [ addr, [ ch ) : void
EventConnectDelayed ( [ addr, ErrorCode errno ) : void
EventConnectRetried ( [ addr, int interval ) : void
EventConnected ( [ addr, [ ch ) : void
EventDisconnected ( [ addr, [ ch ) : void
EventListening ( [ addr, [ ch ) : void
GetSocketOption ( ZmqSocketOption option ) : int

Return the integer-value of the specified option.

If the ReceiveMore option is specified, then 1 is returned if it is true, 0 if it is false. If the Events option is specified, then process any outstanding commands, and return -1 if that throws a TerminatingException. then return an integer that is the bitwise-OR of the PollEvents.PollOut and PollEvents.PollIn flags. Otherwise, cast the specified option value to an integer and return it.

GetSocketOptionX ( ZmqSocketOption option ) : object

Return the value of the specified option as an Object.

If the Handle option is specified, then return the handle of the contained mailbox. If the Events option is specified, then process any outstanding commands, and return -1 if that throws a TerminatingException. then return a PollEvents that is the bitwise-OR of the PollEvents.PollOut and PollEvents.PollIn flags.

HasIn ( ) : bool

These functions are used by the polling mechanism to determine which events are to be reported from this socket.

HasOut ( ) : bool

These functions are used by the polling mechanism to determine which events are to be reported from this socket.

Hiccuped ( NetMQ.Core.Pipe pipe ) : void
InEvent ( ) : void

Handle input-ready events by receiving and processing any incoming commands.

Monitor ( [ addr, SocketEvents events ) : void

Register the given events to monitor on the given endpoint.

OutEvent ( ) : void

Handle output-ready events.

ReadActivated ( NetMQ.Core.Pipe pipe ) : void

Indicate that the given pipe is now ready for reading. Pipe calls this on it's sink in response to ProcessActivateRead. When called upon an instance of SocketBase, this simply calls XReadActivated.

SetSocketOption ( ZmqSocketOption option, object optionValue ) : void

Set the specified socket option.

Stop ( ) : void

Interrupt a blocking call if the socket is stuck in one. This function can be called from a different thread!

TermEndpoint ( [ addr ) : void

Disconnect from the given endpoint.

Terminated ( NetMQ.Core.Pipe pipe ) : void

This gets called by ProcessPipeTermAck or XTerminated to respond to the termination of the given pipe.

TimerEvent ( int id ) : void

In subclasses of SocketBase this is overridden, to handle the expiration of a timer.

ToString ( ) : string

Override the ToString method in order to also show the socket-id.

TryRecv ( Msg &msg, System.TimeSpan timeout ) : bool

Receive a frame into the given msg and return true if successful, false if it timed out.

For timeout, there are three categories of value: TimeSpan.Zero - return false immediately if no message is available SendReceiveConstants.InfiniteTimeout (or a negative value) - wait indefinitely, always returning true Any positive value - return false after the corresponding duration if no message has become available

TrySend ( Msg &msg, System.TimeSpan timeout, bool more ) : bool

Transmit the given Msg across the message-queueing system.

WriteActivated ( NetMQ.Core.Pipe pipe ) : void

When called upon an instance of SocketBase, this simply calls XWriteActivated.

Protected Methods

Method Description
ProcessBind ( NetMQ.Core.Pipe pipe ) : void

Process a Bind command by attaching the given Pipe.

ProcessDestroy ( ) : void

Mark this socket as having been destroyed. Delay actual destruction of the socket.

ProcessStop ( ) : void

Process a termination command on this socket, by stopping monitoring and marking this as terminated.

ProcessTerm ( int linger ) : void

Process a termination request.

SocketBase ( [ parent, int threadId, int socketId ) : System

Create a new SocketBase within the given Ctx, with the specified thread-id and socket-id.

XAttachPipe ( [ pipe, bool icanhasall ) : void

Abstract method for attaching a given pipe to this socket. The concrete implementations are defined by the individual socket types.

XHasIn ( ) : bool

This gets called when incoming messages are ready to be received. On SocketBase, this does nothing and simply returns false.

XHasOut ( ) : bool

This gets called when outgoing messages are ready to be sent out. On SocketBase, this does nothing and simply returns false.

XHiccuped ( [ pipe ) : void
XReadActivated ( [ pipe ) : void

Indicate the given pipe as being ready for reading by this socket. This abstract method gets overridden by the different sockets to provide their own concrete implementation.

XRecv ( Msg &msg ) : bool

Receive a message. The Recv method calls this lower-level method to do the actual receiving. This abstract method gets overridden by the different socket types to provide their concrete implementation of receiving messages.

XSend ( Msg &msg ) : bool

Transmit the given message. The TrySend method calls this to do the actual sending. This abstract method gets overridden by the different socket types to provide their concrete implementation of sending messages.

XSetSocketOption ( ZmqSocketOption option, [ optionValue ) : bool

The default implementation assumes there are no specific socket options for the particular socket type. If not so, overload this method.

XTerminated ( [ pipe ) : void

Abstract method that gets called to signal that the given pipe is to be removed from this socket. The concrete implementations of SocketBase override this to provide their own implementation of how to terminate the pipe.

XWriteActivated ( [ pipe ) : void

Indicate the given pipe as being ready for writing to by this socket. This abstract method gets called by the WriteActivated method and gets overridden by the different sockets to provide their own concrete implementation.

Private Methods

Method Description
AddEndpoint ( [ address, [ endpoint, NetMQ.Core.Pipe pipe ) : void

Take ownership of the given endpoint and register it against the given address.

AttachPipe ( [ pipe, bool icanhasall = false ) : void

Register the given pipe with this socket.

CheckContextTerminated ( ) : void

Throw TerminatingException if the message-queueing system has started terminating.

CheckDestroy ( ) : void

To be called after processing commands or invoking any command handlers explicitly. If required, it will deallocate the socket.

CheckProtocol ( [ protocol ) : void

Check whether the transport protocol, as specified in connect or bind, is available and compatible with the socket type.

The supported protocols are "inproc", "ipc", "tcp", "pgm", and "epgm". If the protocol is either "pgm" or "epgm", then this socket must be of type Pub, Sub, XPub, or XSub.

Create ( ZmqSocketType type, [ parent, int threadId, int socketId ) : SocketBase
DecodeAddress ( [ addr, string &address, string &protocol ) : void

Given a string containing an endpoint address like "tcp://127.0.0.1:5555, break-it-down into the address part ("127.0.0.1:5555") and the protocol part ("tcp").

ExtractFlags ( Msg &msg ) : void

Moves the flags from the message to local variables, to be later retrieved by getsockopt.

GetTypeString ( ) : string
MonitorEvent ( [ monitorEvent ) : void
ProcessCommands ( int timeout, bool throttle ) : void

Processes commands sent to this socket (if any). If timeout is -1, the call blocks until at least one command was processed. If throttle is true, commands are processed at most once in a predefined time period.

StartReaping ( [ poller ) : void

Using this function reaper thread ask the socket to register with its poller.

StopMonitor ( ) : void

If there is a monitor-socket, close it and set monitor-events to 0.

Method Details

Bind() public method

Bind this socket to the given address.
The supported protocols are "inproc", "ipc", "tcp", "pgm", and "epgm". If the protocol is either "pgm" or "epgm", then this socket must be of type Pub, Sub, XPub, or XSub. If the protocol is "inproc", you cannot bind to the same address more than once.
the address specified to bind to must not be already in use The requested protocol is not supported. the socket bind failed No IO thread was found, or the protocol's listener encountered an /// error during initialisation. the specified protocol is not supported the socket type and protocol do not match The socket has been stopped.
public Bind ( [ addr ) : void
addr [ a string denoting the endpoint-address to bind to
return void

BindRandomPort() public method

Bind the specified TCP address to an available port, assigned by the operating system.
uses a protocol other than TCP. The socket has been stopped. The specified address is already in use. No IO thread was found, or the protocol's listener errored during /// initialisation. the socket bind failed
public BindRandomPort ( [ addr ) : int
addr [ a string denoting the endpoint to bind to
return int

CheckDisposed() public method

Throw ObjectDisposedException if this socket is already disposed.
This object is already disposed.
public CheckDisposed ( ) : void
return void

Close() public method

Close this socket. Mark it as disposed, and send ownership of it to the reaper thread to attend to the rest of it's shutdown process.
public Close ( ) : void
return void

Connect() public method

Connect this socket to the given address.
The supported protocols are "inproc", "ipc", "tcp", "pgm", and "epgm". If the protocol is either "pgm" or "epgm", then this socket must be of type Pub, Sub, XPub, or XSub.
The specified address is already in use. No IO thread was found. the specified protocol is not supported the socket type and protocol do not match The socket has been stopped. The given address was not found in the list of endpoints.
public Connect ( [ addr ) : void
addr [ a string denoting the endpoint to connect to
return void

Destroy() public method

Destroy this socket - which means to stop monitoring the queue for messages. This simply calls StopMonitor, and then verifies that the destroyed-flag is set.
public Destroy ( ) : void
return void

EventAcceptFailed() public method

public EventAcceptFailed ( [ addr, ErrorCode errno ) : void
addr [
errno ErrorCode
return void

EventAccepted() public method

public EventAccepted ( [ addr, [ ch ) : void
addr [
ch [
return void

EventBindFailed() public method

public EventBindFailed ( [ addr, ErrorCode errno ) : void
addr [
errno ErrorCode
return void

EventCloseFailed() public method

public EventCloseFailed ( [ addr, ErrorCode errno ) : void
addr [
errno ErrorCode
return void

EventClosed() public method

public EventClosed ( [ addr, [ ch ) : void
addr [
ch [
return void

EventConnectDelayed() public method

public EventConnectDelayed ( [ addr, ErrorCode errno ) : void
addr [
errno ErrorCode
return void

EventConnectRetried() public method

public EventConnectRetried ( [ addr, int interval ) : void
addr [
interval int
return void

EventConnected() public method

public EventConnected ( [ addr, [ ch ) : void
addr [
ch [
return void

EventDisconnected() public method

public EventDisconnected ( [ addr, [ ch ) : void
addr [
ch [
return void

EventListening() public method

public EventListening ( [ addr, [ ch ) : void
addr [
ch [
return void

GetSocketOption() public method

Return the integer-value of the specified option.
If the ReceiveMore option is specified, then 1 is returned if it is true, 0 if it is false. If the Events option is specified, then process any outstanding commands, and return -1 if that throws a TerminatingException. then return an integer that is the bitwise-OR of the PollEvents.PollOut and PollEvents.PollIn flags. Otherwise, cast the specified option value to an integer and return it.
The socket has been stopped.
public GetSocketOption ( ZmqSocketOption option ) : int
option ZmqSocketOption which option to get
return int

GetSocketOptionX() public method

Return the value of the specified option as an Object.
If the Handle option is specified, then return the handle of the contained mailbox. If the Events option is specified, then process any outstanding commands, and return -1 if that throws a TerminatingException. then return a PollEvents that is the bitwise-OR of the PollEvents.PollOut and PollEvents.PollIn flags.
The socket has already been stopped.
public GetSocketOptionX ( ZmqSocketOption option ) : object
option ZmqSocketOption which option to get
return object

HasIn() public method

These functions are used by the polling mechanism to determine which events are to be reported from this socket.
public HasIn ( ) : bool
return bool

HasOut() public method

These functions are used by the polling mechanism to determine which events are to be reported from this socket.
public HasOut ( ) : bool
return bool

Hiccuped() public method

public Hiccuped ( NetMQ.Core.Pipe pipe ) : void
pipe NetMQ.Core.Pipe
return void

InEvent() public method

Handle input-ready events by receiving and processing any incoming commands.
public InEvent ( ) : void
return void

Monitor() public method

Register the given events to monitor on the given endpoint.
Maximum number of sockets reached. The protocol of is not supported. The socket has been stopped.
public Monitor ( [ addr, SocketEvents events ) : void
addr [ a string denoting the endpoint to monitor. If this is null - monitoring is stopped.
events SocketEvents the SocketEvent to monitor for
return void

OutEvent() public method

Handle output-ready events.
This is not supported on instances of the parent class SocketBase.
public OutEvent ( ) : void
return void

ProcessBind() protected method

Process a Bind command by attaching the given Pipe.
protected ProcessBind ( NetMQ.Core.Pipe pipe ) : void
pipe NetMQ.Core.Pipe the Pipe to attach
return void

ProcessDestroy() protected method

Mark this socket as having been destroyed. Delay actual destruction of the socket.
protected ProcessDestroy ( ) : void
return void

ProcessStop() protected method

Process a termination command on this socket, by stopping monitoring and marking this as terminated.
protected ProcessStop ( ) : void
return void

ProcessTerm() protected method

Process a termination request.
protected ProcessTerm ( int linger ) : void
linger int a time (in milliseconds) for this to linger before actually going away. -1 means infinite.
return void

ReadActivated() public method

Indicate that the given pipe is now ready for reading. Pipe calls this on it's sink in response to ProcessActivateRead. When called upon an instance of SocketBase, this simply calls XReadActivated.
public ReadActivated ( NetMQ.Core.Pipe pipe ) : void
pipe NetMQ.Core.Pipe the pipe to indicate is ready for reading
return void

SetSocketOption() public method

Set the specified socket option.
The socket has been stopped.
public SetSocketOption ( ZmqSocketOption option, object optionValue ) : void
option ZmqSocketOption which option to set
optionValue object the value to set the option to
return void

SocketBase() protected method

Create a new SocketBase within the given Ctx, with the specified thread-id and socket-id.
protected SocketBase ( [ parent, int threadId, int socketId ) : System
parent [ the Ctx context that this socket will live within
threadId int the id of the thread upon which this socket will execute
socketId int the integer id for the new socket
return System

Stop() public method

Interrupt a blocking call if the socket is stuck in one. This function can be called from a different thread!
public Stop ( ) : void
return void

TermEndpoint() public method

Disconnect from the given endpoint.
is null. Endpoint was not found and cannot be disconnected. The specified protocol must be valid. The socket has been stopped.
public TermEndpoint ( [ addr ) : void
addr [ the endpoint to disconnect from
return void

Terminated() public method

This gets called by ProcessPipeTermAck or XTerminated to respond to the termination of the given pipe.
public Terminated ( NetMQ.Core.Pipe pipe ) : void
pipe NetMQ.Core.Pipe the pipe that was terminated
return void

TimerEvent() public method

In subclasses of SocketBase this is overridden, to handle the expiration of a timer.
You must not call TimerEvent on an instance of class SocketBase.
public TimerEvent ( int id ) : void
id int an integer used to identify the timer
return void

ToString() public method

Override the ToString method in order to also show the socket-id.
public ToString ( ) : string
return string

TryRecv() public method

Receive a frame into the given msg and return true if successful, false if it timed out.
For timeout, there are three categories of value: TimeSpan.Zero - return false immediately if no message is available SendReceiveConstants.InfiniteTimeout (or a negative value) - wait indefinitely, always returning true Any positive value - return false after the corresponding duration if no message has become available
the Msg must already have been uninitialised The socket must not already be stopped.
public TryRecv ( Msg &msg, System.TimeSpan timeout ) : bool
msg Msg the Msg to read the received message into
timeout System.TimeSpan this controls whether the call blocks, and for how long.
return bool

TrySend() public method

Transmit the given Msg across the message-queueing system.
The socket has been stopped. is not initialised.
public TrySend ( Msg &msg, System.TimeSpan timeout, bool more ) : bool
msg Msg The to send.
timeout System.TimeSpan The timeout to wait before returning false. Pass to disable timeout.
more bool Whether this message will contain another frame after this one.
return bool

WriteActivated() public method

When called upon an instance of SocketBase, this simply calls XWriteActivated.
public WriteActivated ( NetMQ.Core.Pipe pipe ) : void
pipe NetMQ.Core.Pipe the pipe to indicate is ready for writing
return void

XAttachPipe() protected abstract method

Abstract method for attaching a given pipe to this socket. The concrete implementations are defined by the individual socket types.
protected abstract XAttachPipe ( [ pipe, bool icanhasall ) : void
pipe [ the Pipe to attach
icanhasall bool if true - subscribe to all data on the pipe
return void

XHasIn() protected method

This gets called when incoming messages are ready to be received. On SocketBase, this does nothing and simply returns false.
protected XHasIn ( ) : bool
return bool

XHasOut() protected method

This gets called when outgoing messages are ready to be sent out. On SocketBase, this does nothing and simply returns false.
protected XHasOut ( ) : bool
return bool

XHiccuped() protected method

protected XHiccuped ( [ pipe ) : void
pipe [
return void

XReadActivated() protected method

Indicate the given pipe as being ready for reading by this socket. This abstract method gets overridden by the different sockets to provide their own concrete implementation.
protected XReadActivated ( [ pipe ) : void
pipe [ the Pipe that is now becoming available for reading
return void

XRecv() protected method

Receive a message. The Recv method calls this lower-level method to do the actual receiving. This abstract method gets overridden by the different socket types to provide their concrete implementation of receiving messages.
protected XRecv ( Msg &msg ) : bool
msg Msg the Msg to receive the message into
return bool

XSend() protected method

Transmit the given message. The TrySend method calls this to do the actual sending. This abstract method gets overridden by the different socket types to provide their concrete implementation of sending messages.
protected XSend ( Msg &msg ) : bool
msg Msg the message to transmit
return bool

XSetSocketOption() protected method

The default implementation assumes there are no specific socket options for the particular socket type. If not so, overload this method.
protected XSetSocketOption ( ZmqSocketOption option, [ optionValue ) : bool
option ZmqSocketOption a ZmqSocketOption specifying which option to set
optionValue [ an Object that is the value to set the option to
return bool

XTerminated() protected abstract method

Abstract method that gets called to signal that the given pipe is to be removed from this socket. The concrete implementations of SocketBase override this to provide their own implementation of how to terminate the pipe.
protected abstract XTerminated ( [ pipe ) : void
pipe [ the Pipe that is being removed
return void

XWriteActivated() protected method

Indicate the given pipe as being ready for writing to by this socket. This abstract method gets called by the WriteActivated method and gets overridden by the different sockets to provide their own concrete implementation.
protected XWriteActivated ( [ pipe ) : void
pipe [ the Pipe that is now becoming available for writing
return void