Example #1
0
        public unsafe void Execute(UdpSocketSendResult target)
        {
            target.Pin(buffer.Data);

            Overlapped overlapped = new Overlapped {
                AsyncResult = target
            };
            NativeOverlapped *native    = overlapped.UnsafePack(null, null);
            IntPtr            reference = Marshal.UnsafeAddrOfPinnedArrayElement(buffer.Data, buffer.Offset);

            TcpSocketInterop.WSABuffer data = new TcpSocketInterop.WSABuffer
            {
                length = buffer.Count,
                buffer = reference
            };

            byte[] address       = endpoint.Address.GetAddressBytes();
            byte[] addressData   = { 0x02, 0x00, (byte)(endpoint.Port / 256), (byte)(endpoint.Port % 256), address[0], address[1], address[2], address[3], 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            IntPtr addressBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(addressData, 0);

            target.Pin(addressData);

            int  written;
            uint result = UdpSocketInterop.WSASendTo(handle, &data, 1, out written, 0, addressBuffer, addressData.Length, native, IntPtr.Zero);
            uint error  = TcpSocketInterop.WSAGetLastError();

            if (result != 0 && error != 997)
            {
                target.Fail(error);
            }
        }
Example #2
0
        public void Send(IPEndPoint endpoint, SocketBuffer buffer, UdpSocketSendCallback callback)
        {
            UdpSocketSendRoutine routine = new UdpSocketSendRoutine(handle, endpoint, buffer);
            UdpSocketSendResult  result  = new UdpSocketSendResult
            {
                Socket   = this,
                Buffer   = buffer,
                OnSent   = callback,
                Endpoint = endpoint
            };

            routine.Execute(result);
        }