C# AsyncIO
来源:互联网 发布:加工中心3d编程培训 编辑:程序博客网 时间:2024/06/05 18:30
这一天看NETMQ发现里面使用的是IOCP是思想,以前自己老是想找一个类是dll,这次终于找到了,特此记录一下.
git: https://github.com/somdoron/AsyncIO
demo:
AsyncIO
AsyncIO is portable high performance sockets library for .Net. The library is based on Windows IO Completion ports.
.Net Socket library doesn't give control over the threads and doesn't expose the IO completion port API, AsyncIO give full control over the threads and allow the developer to create high performance servers.
On Mono the library fall down to mono implementation but still give completion port like API.
Installation
You can install AsyncIO from nuget.
Using
Using AsyncIO is very similiar to using .Net Socket, to get the completion event of the operation you need to call GetQueuedCompletionStatus method of the completion port.
static void Main(string[] args) { CompletionPort completionPort = CompletionPort.Create(); AutoResetEvent listenerEvent = new AutoResetEvent(false); AutoResetEvent clientEvent = new AutoResetEvent(false); AutoResetEvent serverEvent = new AutoResetEvent(false); AsyncSocket listener = AsyncSocket.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); completionPort.AssociateSocket(listener, listenerEvent); AsyncSocket server = AsyncSocket.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); completionPort.AssociateSocket(server, serverEvent); AsyncSocket client = AsyncSocket.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); completionPort.AssociateSocket(client, clientEvent); Task.Factory.StartNew(() => { CompletionStatus completionStatus; while (true) { var result = completionPort.GetQueuedCompletionStatus(-1, out completionStatus); if (result) { Console.WriteLine("{0} {1} {2}", completionStatus.SocketError, completionStatus.OperationType, completionStatus.BytesTransferred); if (completionStatus.State != null) { AutoResetEvent resetEvent = (AutoResetEvent)completionStatus.State; resetEvent.Set(); } } } }); listener.Bind(IPAddress.Any, 5555); listener.Listen(1); client.Connect("localhost", 5555); listener.Accept(server); listenerEvent.WaitOne(); clientEvent.WaitOne(); byte[] sendBuffer = new byte[1] { 2 }; byte[] recvBuffer = new byte[1]; client.Send(sendBuffer); server.Receive(recvBuffer); clientEvent.WaitOne(); serverEvent.WaitOne(); server.Dispose(); client.Dispose(); }
- C# AsyncIO
- asyncio
- asyncio
- asyncio
- python asyncio
- asyncio 模块
- Python asyncio文档翻译--asyncio.Future
- asyncio学习(1)
- 【asyncio】python异步IO
- asyncio 官方文档
- Python标准模块--asyncio
- Flink AsyncIO特性测评
- Python asyncio文档翻译
- aiohttp,asyncio, RunTimeError
- Python3 asyncio 例程
- python asyncio学习记录
- Python -asyncio笔记
- Grequests VS aiohttp+asyncio
- HDU 4179 Difficult Routes
- HDU 1688 Sightseeing
- HDU 3873 Invade the Mars
- HDU 3311 Dig The Wells(spfa模板)
- HDU 2888 Check Corners
- C# AsyncIO
- HDU 2377 Bus Pass
- 如何使用Kotlin进行Android开发
- string
- HDU 2833 WuKong
- HDU 2433 Travel
- HDU 2482 Transit search
- HDU 3191 How Many Paths Are There
- HDU 4114 Disney's FastPass Time