示例#1
0
        public unsafe void Execute(UdpSocketReceiveResult target)
        {
            target.Pin(buffer.Data);

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

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

            byte[] addressData    = new byte[16];
            IntPtr addressPointer = Marshal.UnsafeAddrOfPinnedArrayElement(addressData, 0);

            target.Address = addressData;
            target.Pin(addressData);

            int  read, flags = 0, size = addressData.Length;
            int  result = UdpSocketInterop.WSARecvFrom(handle, &data, 1, out read, ref flags, addressPointer, ref size, native, IntPtr.Zero);
            uint error  = TcpSocketInterop.GetLastError();

            if (result == -1 && error != 997)
            {
                target.Fail(error);
            }
        }
示例#2
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);
            }
        }
示例#3
0
        public void Execute(IntPtr handle)
        {
            int  reference = value;
            uint result    = UdpSocketInterop.setsockopt(handle, level, option, ref reference, sizeof(int));

            if (result != 0)
            {
            }
        }
示例#4
0
        public UdpSocket Udp()
        {
            IntPtr handle = UdpSocketInterop.WSASocket(2, 2, 17, IntPtr.Zero, 0, 1);

            if (handle == new IntPtr(-1))
            {
                throw new Exception();
            }

            return(new UdpSocketInstance(handle, worker));
        }
示例#5
0
 public void Dispose()
 {
     UdpSocketInterop.closesocket(handle);
 }