Class MpxSocket<TTransport>
Base for MpxSockets implementation. An MpxSocket represents an asynchronous bi-directional channel of communication
that delivers binary/wire messages of flexible size.
The socket is NOT THREAD SAFE for calling Send() from parallel threads. Send() is done synchronously on the
calling thread, i.e. the sender waits until the data is written into the OS socket buff.
Receive is invoked by internal/system/io thread asynchronously and should not block for long (seconds)
Inheritance
System.Object
MpxSocket<TTransport>
Implements
System.IDisposable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Assembly: Azos.dll
Syntax
public abstract class MpxSocket<TTransport> : DisposableObject, IDisposable where TTransport : Transport, IMpxTransport
Type Parameters
Name |
Description |
TTransport |
|
Constructors
MpxSocket(TTransport, IPEndPoint, ClientSite, MpxSocketReceiveAction<TTransport>)
Declaration
protected MpxSocket(TTransport transport, IPEndPoint endPoint, ClientSite clientSite, MpxSocketReceiveAction<TTransport> receiveAction)
Parameters
Fields
m_ClientSite
Declaration
protected readonly ClientSite m_ClientSite
Field Value
m_Disposing
Declaration
protected volatile bool m_Disposing
Field Value
Type |
Description |
System.Boolean |
|
m_EndPoint
Declaration
protected readonly IPEndPoint m_EndPoint
Field Value
Type |
Description |
System.Net.IPEndPoint |
|
m_LastIdleManagerVisit
Declaration
protected DateTime? m_LastIdleManagerVisit
Field Value
Type |
Description |
System.Nullable<System.DateTime> |
|
m_ReceiveChunk
Declaration
protected MemChunk m_ReceiveChunk
Field Value
m_SendChunk
Declaration
protected MemChunk m_SendChunk
Field Value
m_Socket
Declaration
protected Socket m_Socket
Field Value
Type |
Description |
System.Net.Sockets.Socket |
|
m_Transport
Declaration
protected readonly TTransport m_Transport
Field Value
Type |
Description |
TTransport |
|
Properties
Active
True when socket is not disposing and runtime is not shutting down
Declaration
public bool Active { get; }
Property Value
Type |
Description |
System.Boolean |
|
ClientSite
Returns client site for the computer that initiated the call.
Server socket returns the transmitted value from client. Client socket returns the one that was
sent to server upon handshake
Declaration
public ClientSite ClientSite { get; }
Property Value
EndPoint
Returns IP End point that this socket services, remote server for client socket and remote client for server sockets
Declaration
public IPEndPoint EndPoint { get; }
Property Value
Type |
Description |
System.Net.IPEndPoint |
|
LastIdleManagerVisit
Returns timestamp of last manager visit since then no traffic came through. Null indicates that traffic came though
and socket has not been idle since last visit. Manager is an extrenal visitor that closes idle sockets
Declaration
public DateTime? LastIdleManagerVisit { get; }
Property Value
Type |
Description |
System.Nullable<System.DateTime> |
|
Socket
Returns the underlying socket
Declaration
public Socket Socket { get; }
Property Value
Type |
Description |
System.Net.Sockets.Socket |
|
Transport
Returns transport that this socket is under
Declaration
public TTransport Transport { get; }
Property Value
Type |
Description |
TTransport |
|
Methods
AcceptManagerVisit(DateTime)
Override to perform maintenance i.e. trim excessive m_SendChunk size etc..
This method is called by Glue/Binding/Transport runtime.
Also resets last last idle manager visit timestamp which is used for socket closing
Declaration
public virtual void AcceptManagerVisit(DateTime when)
Parameters
Type |
Name |
Description |
System.DateTime |
when |
|
Destructor()
Declaration
protected override void Destructor()
Overrides
DoReleaseMemChunksAfterAsyncOperations()
Do not call this method, override only when freeing more than 2 standard chunks (send/recv)
Declaration
protected virtual void DoReleaseMemChunksAfterAsyncOperations()
DoSend(WireMsg)
Declaration
protected abstract void DoSend(WireMsg data)
Parameters
GetSendChunk(Int32)
Reserves a chunk of memory of the suggested size for network send operation.
The buffer must be released by a call to ReleaseSendBuffer().
Keep in mind that this method is NOT RE-ENTRANT by this or any other thread until corresponding ReleaseSendChunk() is called.
MpxSocket is not thread safe for sends in general.
Declaration
public virtual MemChunk GetSendChunk(int desiredSize = 0)
Parameters
Type |
Name |
Description |
System.Int32 |
desiredSize |
|
Returns
InvokeReceive(WireMsg)
Calls ReceiveAction callback guarding for possible unhandled receive action errors
Declaration
protected void InvokeReceive(WireMsg msg)
Parameters
ReleaseMemChunksAfterAsyncOperations()
Releases socket memory chunks. This method MUST BE called AFTER all pending async IO is done,
otherwise the chunks may get released to the pool and get corrupted by the prior operation
Declaration
protected void ReleaseMemChunksAfterAsyncOperations()
ReleaseSendChunk()
Releases previously reserved buffer, i.e. may trim excess allocation after a large message
Declaration
public virtual void ReleaseSendChunk()
Send(WireMsg)
Adds the specified socket msg to the outgoing stack.
This is a synchronous blocking call that executes until the data is written
into socket stack (but not necessarily delivered). If send error occurs then socket is
marked as !Active (Disposed)
Declaration
public void Send(WireMsg data)
Parameters
Implements
System.IDisposable
Extension Methods