Example #1
0
        public void Connect(IPEndPoint ipEndPoint, Action <Exception> callback)
        {
            CheckDisposed();

            Ensure.ArgumentNotNull(ipEndPoint, "ipEndPoint");
            Ensure.ArgumentNotNull(callback, "callback");
            Ensure.AddressFamily(ipEndPoint.Address);

            ConnectRequest cpr = new ConnectRequest();

            cpr.Callback = (status, cpr2) => Ensure.Success(status, callback);

            int r;

            if (ipEndPoint.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                sockaddr_in address = UV.ToStruct(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                r = uv_tcp_connect(cpr.Handle, NativeHandle, ref address, CallbackPermaRequest.CallbackDelegate);
            }
            else
            {
                sockaddr_in6 address = UV.ToStruct6(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                r = uv_tcp_connect(cpr.Handle, NativeHandle, ref address, CallbackPermaRequest.CallbackDelegate);
            }
            Ensure.Success(r);
        }
Example #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;

            if (UV.isUnix)
            {
                UnixBufferStruct[] buf = new UnixBufferStruct[1];
                buf[0] = new UnixBufferStruct(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);
                }
            }
            else
            {
                WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                buf[0] = new WindowsBufferStruct(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);
        }
Example #3
0
        public void Send(IPAddress ipAddress, int port, byte[] data, int index, int count, Action <bool> callback)
        {
            Ensure.ArgumentNotNull(ipAddress, "ipAddress");
            Ensure.AddressFamily(ipAddress);
            Ensure.ArgumentNotNull(data, "data");

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

            cpr.Callback += (status, cpr2) => {
                datagchandle.Free();
                if (callback != null)
                {
                    callback(status == 0);
                }
            };

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

            int r;

            if (UV.isUnix)
            {
                UnixBufferStruct[] buf = new UnixBufferStruct[1];
                buf[0] = new UnixBufferStruct(ptr, count);

                if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    r = uv_udp_send_unix(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip4_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                }
                else
                {
                    r = uv_udp_send6_unix(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip6_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                }
            }
            else
            {
                WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                buf[0] = new WindowsBufferStruct(ptr, count);

                if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    r = uv_udp_send_win(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip4_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                }
                else
                {
                    r = uv_udp_send6_win(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip6_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                }
            }
            Ensure.Success(r, Loop);
        }
Example #4
0
        public void Bind(IPAddress ipAddress, int port)
        {
            Ensure.ArgumentNotNull(ipAddress, "ipAddress");
            Ensure.AddressFamily(ipAddress);

            int r;

            if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                r = uv_tcp_bind(NativeHandle, UV.uv_ip4_addr(ipAddress.ToString(), port));
            }
            else
            {
                r = uv_tcp_bind6(NativeHandle, UV.uv_ip6_addr(ipAddress.ToString(), port));
            }
            Ensure.Success(r, Loop);
        }
Example #5
0
        public void Bind(IPEndPoint ipEndPoint)
        {
            Ensure.ArgumentNotNull(ipEndPoint, "ipEndPoint");
            Ensure.AddressFamily(ipEndPoint.Address);
            int r;

            if (ipEndPoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                sockaddr_in address = UV.ToStruct(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                r = uv_tcp_bind(NativeHandle, ref address, 0);
            }
            else
            {
                sockaddr_in6 address = UV.ToStruct6(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                r = uv_tcp_bind(NativeHandle, ref address, 0);
            }
            Ensure.Success(r);
        }
Example #6
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);
        }
Example #7
0
        void Bind(IPAddress ipAddress, int port, short flags)
        {
            Ensure.AddressFamily(ipAddress);

            dualstack = (flags & (short)uv_udp_flags.UV_UDP_IPV6ONLY) == 0 &&
                        ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6;

            int r;

            if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                r = uv_udp_bind(NativeHandle, UV.uv_ip4_addr(ipAddress.ToString(), port), 0);
            }
            else
            {
                r = uv_udp_bind6(NativeHandle, UV.uv_ip6_addr(ipAddress.ToString(), port), 0);
            }
            Ensure.Success(r, Loop);
        }
Example #8
0
        void Bind(IPAddress ipAddress, int port, short flags)
        {
            Ensure.AddressFamily(ipAddress);

            dualstack = (flags & (short)uv_udp_flags.UV_UDP_IPV6ONLY) == 0 &&
                        ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6;

            int r;

            if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                sockaddr_in address = UV.ToStruct(ipAddress.ToString(), port);
                r = uv_udp_bind(NativeHandle, ref address, 0);
            }
            else
            {
                sockaddr_in6 address = UV.ToStruct6(ipAddress.ToString(), port);
                r = uv_udp_bind(NativeHandle, ref address, 0);
            }
            Ensure.Success(r);
        }