public unsafe RioSocketPool(RioFixedBufferPool sendPool, RioFixedBufferPool receivePool, uint maxOutstandingReceive = 1024, uint maxOutstandingSend = 1024, uint maxOutsandingCompletions = 2048) { MaxOutstandingReceive = maxOutstandingReceive; MaxOutstandingSend = maxOutstandingSend; MaxOutsandingCompletions = maxOutsandingCompletions; SendBufferPool = sendPool; ReceiveBufferPool = receivePool; var version = new Version(2, 2); WSAData data; var result = WinSock.WSAStartup((short)version.Raw, out data); if (result != 0) { WinSock.ThrowLastWSAError(); } RioStatic.Initalize(); if ((ReceiveCompletionPort = Kernel32.CreateIoCompletionPort((IntPtr)(-1), IntPtr.Zero, 0, 1)) == IntPtr.Zero) { Kernel32.ThrowLastError(); } if ((SendCompletionPort = Kernel32.CreateIoCompletionPort((IntPtr)(-1), IntPtr.Zero, 0, 1)) == IntPtr.Zero) { Kernel32.ThrowLastError(); } _sendBufferId = RioStatic.RegisterBuffer(SendBufferPool.BufferPointer, (uint)SendBufferPool.TotalLength); WinSock.ThrowLastWSAError(); SendBufferPool.SetBufferId(_sendBufferId); _reciveBufferId = RioStatic.RegisterBuffer(ReceiveBufferPool.BufferPointer, (uint)ReceiveBufferPool.TotalLength); WinSock.ThrowLastWSAError(); ReceiveBufferPool.SetBufferId(_reciveBufferId); var sendCompletionMethod = new RIO_NOTIFICATION_COMPLETION() { Type = RIO_NOTIFICATION_COMPLETION_TYPE.IOCP_COMPLETION, Iocp = new RIO_NOTIFICATION_COMPLETION_IOCP() { IocpHandle = SendCompletionPort, QueueCorrelation = 0, Overlapped = (NativeOverlapped *)-1 } }; if ((SendCompletionQueue = RioStatic.CreateCompletionQueue(MaxOutsandingCompletions, sendCompletionMethod)) == IntPtr.Zero) { WinSock.ThrowLastWSAError(); } var receiveCompletionMethod = new RIO_NOTIFICATION_COMPLETION() { Type = RIO_NOTIFICATION_COMPLETION_TYPE.IOCP_COMPLETION, Iocp = new RIO_NOTIFICATION_COMPLETION_IOCP() { IocpHandle = ReceiveCompletionPort, QueueCorrelation = 0, Overlapped = (NativeOverlapped *)-1 } }; if ((ReceiveCompletionQueue = RioStatic.CreateCompletionQueue(MaxOutsandingCompletions, receiveCompletionMethod)) == IntPtr.Zero) { WinSock.ThrowLastWSAError(); } Thread receiveThread = new Thread(ProcessReceiveCompletes); receiveThread.IsBackground = true; receiveThread.Start(); Thread sendThread = new Thread(ProcessSendCompletes); sendThread.IsBackground = true; sendThread.Start(); }
public unsafe RioSocketPool(RioFixedBufferPool sendPool, RioFixedBufferPool receivePool, uint maxOutstandingReceive = 1024, uint maxOutstandingSend = 1024, uint maxOutsandingCompletions = 2048) { MaxOutstandingReceive = maxOutstandingReceive; MaxOutstandingSend = maxOutstandingSend; MaxOutsandingCompletions = maxOutsandingCompletions; SendBufferPool = sendPool; ReceiveBufferPool = receivePool; var version = new Version(2, 2); WSAData data; var result = WinSock.WSAStartup((short)version.Raw, out data); if (result != 0) WinSock.ThrowLastWSAError(); RioStatic.Initalize(); if ((ReceiveCompletionPort = Kernel32.CreateIoCompletionPort((IntPtr)(-1), IntPtr.Zero, 0, 1)) == IntPtr.Zero) Kernel32.ThrowLastError(); if ((SendCompletionPort = Kernel32.CreateIoCompletionPort((IntPtr)(-1), IntPtr.Zero, 0, 1)) == IntPtr.Zero) Kernel32.ThrowLastError(); _sendBufferId = RioStatic.RegisterBuffer(SendBufferPool.BufferPointer, (uint)SendBufferPool.TotalLength); WinSock.ThrowLastWSAError(); SendBufferPool.SetBufferId(_sendBufferId); _reciveBufferId = RioStatic.RegisterBuffer(ReceiveBufferPool.BufferPointer, (uint)ReceiveBufferPool.TotalLength); WinSock.ThrowLastWSAError(); ReceiveBufferPool.SetBufferId(_reciveBufferId); var sendCompletionMethod = new RIO_NOTIFICATION_COMPLETION() { Type = RIO_NOTIFICATION_COMPLETION_TYPE.IOCP_COMPLETION, Iocp = new RIO_NOTIFICATION_COMPLETION_IOCP() { IocpHandle = SendCompletionPort, QueueCorrelation = 0, Overlapped = (NativeOverlapped*)-1 } }; if ((SendCompletionQueue = RioStatic.CreateCompletionQueue(MaxOutsandingCompletions, sendCompletionMethod)) == IntPtr.Zero) WinSock.ThrowLastWSAError(); var receiveCompletionMethod = new RIO_NOTIFICATION_COMPLETION() { Type = RIO_NOTIFICATION_COMPLETION_TYPE.IOCP_COMPLETION, Iocp = new RIO_NOTIFICATION_COMPLETION_IOCP() { IocpHandle = ReceiveCompletionPort, QueueCorrelation = 0, Overlapped = (NativeOverlapped*)-1 } }; if ((ReceiveCompletionQueue = RioStatic.CreateCompletionQueue(MaxOutsandingCompletions, receiveCompletionMethod)) == IntPtr.Zero) WinSock.ThrowLastWSAError(); Thread receiveThread = new Thread(ProcessReceiveCompletes); receiveThread.IsBackground = true; receiveThread.Start(); Thread sendThread = new Thread(ProcessSendCompletes); sendThread.IsBackground = true; sendThread.Start(); }