public static unsafe SocketError ConnectAsync(Socket socket, SafeCloseSocket handle, byte[] socketAddress, int socketAddressLen, ConnectOverlappedAsyncResult asyncResult)
        {
            // This will pin the socketAddress buffer.
            asyncResult.SetUnmanagedStructures(socketAddress);

            int ignoreBytesSent;

            if (!socket.ConnectEx(
                    handle,
                    Marshal.UnsafeAddrOfPinnedArrayElement(socketAddress, 0),
                    socketAddressLen,
                    IntPtr.Zero,
                    0,
                    out ignoreBytesSent,
                    asyncResult.OverlappedHandle))
            {
                return(GetLastSocketError());
            }

            return(SocketError.Success);
        }
示例#2
0
        public static unsafe SocketError ConnectAsync(Socket socket, SafeCloseSocket handle, byte[] socketAddress, int socketAddressLen, ConnectOverlappedAsyncResult asyncResult)
        {
            // This will pin the socketAddress buffer.
            asyncResult.SetUnmanagedStructures(socketAddress);
            try
            {
                int  ignoreBytesSent;
                bool success = socket.ConnectEx(
                    handle,
                    Marshal.UnsafeAddrOfPinnedArrayElement(socketAddress, 0),
                    socketAddressLen,
                    IntPtr.Zero,
                    0,
                    out ignoreBytesSent,
                    asyncResult.OverlappedHandle);

                return(asyncResult.ProcessOverlappedResult(success, 0));
            }
            catch
            {
                asyncResult.ReleaseUnmanagedStructures();
                throw;
            }
        }
        internal unsafe SocketError DoOperationConnect(Socket socket, SafeCloseSocket handle, out int bytesTransferred)
        {
            PrepareIOCPOperation();

            SocketError socketError = SocketError.Success;

            if (!socket.ConnectEx(
                handle,
                _ptrSocketAddressBuffer,
                _socketAddress.Size,
                _ptrSingleBuffer,
                Count,
                out bytesTransferred,
                _ptrNativeOverlapped))
            {
                socketError = SocketPal.GetLastSocketError();
            }

            return socketError;
        }
示例#4
0
        public static unsafe SocketError ConnectAsync(Socket socket, SafeCloseSocket handle, byte[] socketAddress, int socketAddressLen, ConnectOverlappedAsyncResult asyncResult)
        {
            // This will pin the socketAddress buffer.
            asyncResult.SetUnmanagedStructures(socketAddress);

            int ignoreBytesSent;
            if (!socket.ConnectEx(
                handle,
                Marshal.UnsafeAddrOfPinnedArrayElement(socketAddress, 0),
                socketAddressLen,
                IntPtr.Zero,
                0,
                out ignoreBytesSent,
                asyncResult.OverlappedHandle))
            {
                return GetLastSocketError();
            }

            return SocketError.Success;
        }