The main feature of these enhancements is the avoidance of the repeated allocation and synchronization of objects during high-volume asynchronous socket I/O. The Begin/End design pattern currently implemented by the Socket class for asynchronous socket I/O requires a System.IAsyncResult object be allocated for each asynchronous socket operation.
Allocate a new SocketAsyncEventArgs context object, or get a free one from an application pool.
Set properties on the context object to the operation about to be performed (the callback delegate method and data buffer, for example).
Call the appropriate socket method (xxxAsync) to initiate the asynchronous operation.
If the asynchronous socket method (xxxAsync) returns true in the callback, query the context properties for completion status.
If the asynchronous socket method (xxxAsync) returns false in the callback, the operation completed synchronously. The context properties may be queried for the operation result.
Reuse the context for another operation, put it back in the pool, or discard it.
while (IsListening)
{
var saea = _acceptSaeaPool.Take();
var socketError = await _listener.AcceptAsync(saea);
if (socketError == SocketError.Success)
{
var acceptedSocket = saea.Saea.AcceptSocket;
}
_acceptSaeaPool.Return(saea);
}
The following functions are supported for Windows Store apps on Windows 8.1, Windows Server 2012 R2, and later. Microsoft Visual Studio 2013 Update 3 or later is required for Windows Store apps.
RIOCloseCompletionQueue
RIOCreateCompletionQueue
RIOCreateRequestQueue
RIODequeueCompletion
RIODeregisterBuffer
RIONotify
RIOReceive
RIOReceiveEx
RIORegisterBuffer
RIOResizeCompletionQueue
RIOResizeRequestQueue
RIOSend
RIOSendEx
到目前为止,.NET Framework 还没有推出对 RIO 的支持,所以若想在 C# 中实现 RIO 则只能通过 P/Invoke 方式,RioSharp 是开源项目中的一个比较完整的实现。