コード例 #1
0
        public CompletionPort()
        {
            m_completionPortHandle =
                UnsafeMethods.CreateIoCompletionPort(UnsafeMethods.INVALID_HANDLE_VALUE, InvalidCompletionPort, IntPtr.Zero, 1);

            if (m_completionPortHandle == InvalidCompletionPort || m_completionPortHandle == InvalidCompletionPortMinusOne)
            {
                throw new Win32Exception();
            }

            m_signalQueue = new ConcurrentQueue <object>();
        }
コード例 #2
0
        public override void AssociateSocket(AsyncSocket socket, object state)
        {
            if (!(socket is Windows.Socket))
            {
                throw new ArgumentException("socket must be of type Windows.Socket", "socket");
            }

            Socket windowsSocket = socket as Socket;

            if (windowsSocket.CompletionPort != this)
            {
                IntPtr result = UnsafeMethods.CreateIoCompletionPort(windowsSocket.Handle, m_completionPortHandle,
                                                                     SocketCompletionKey, 0);

                if (result == InvalidCompletionPort || result == InvalidCompletionPortMinusOne)
                {
                    throw new Win32Exception();
                }
            }

            windowsSocket.SetCompletionPort(this, state);
        }