Beispiel #1
0
        internal static void Bind(Handle handle, bind bind, bind6 bind6, IPAddress ipAddress, int port, bool dualstack)
        {
            Ensure.AddressFamily(ipAddress);

            int r;

            if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                sockaddr_in address = UV.ToStruct(ipAddress.ToString(), port);
                r = bind(handle.NativeHandle, ref address, 0);
            }
            else
            {
                sockaddr_in6 address = UV.ToStruct6(ipAddress.ToString(), port);
                r = bind6(handle.NativeHandle, ref address, (uint)(dualstack ? 0 : 1));
            }
            Ensure.Success(r);
        }
Beispiel #2
0
        public void Send(UdpMessage message, Action <Exception> callback)
        {
            CheckDisposed();

            Ensure.ArgumentNotNull(message.EndPoint, "message EndPoint");
            Ensure.AddressFamily(message.EndPoint.Address);

            var ipEndPoint = message.EndPoint;
            var data       = message.Payload;

            GCHandle             datagchandle = GCHandle.Alloc(data.Array, GCHandleType.Pinned);
            CallbackPermaRequest cpr          = new CallbackPermaRequest(RequestType.UV_UDP_SEND);

            cpr.Callback = (status, cpr2) =>
            {
                datagchandle.Free();
                Ensure.Success(status, callback);
            };

            var ptr = (IntPtr)(datagchandle.AddrOfPinnedObject().ToInt64() + data.Offset);

            int r;

            uv_buf_t[] buf = new uv_buf_t[] { new uv_buf_t(ptr, data.Count) };

            if (ipEndPoint.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                sockaddr_in address = UV.ToStruct(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                r = uv_udp_send(cpr.Handle, NativeHandle, buf, 1, ref address, CallbackPermaRequest.CallbackDelegate);
            }
            else
            {
                sockaddr_in6 address = UV.ToStruct6(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                r = uv_udp_send(cpr.Handle, NativeHandle, buf, 1, ref address, CallbackPermaRequest.CallbackDelegate);
            }
            Ensure.Success(r);
        }