예제 #1
0
파일: Tcp.cs 프로젝트: txdv/LibuvSharp
        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);
        }
예제 #2
0
파일: Udp.cs 프로젝트: txdv/LibuvSharp
        unsafe public int TrySend(UdpMessage message)
        {
            Ensure.ArgumentNotNull(message, "message");

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

            fixed(byte *bytePtr = data.Array)
            {
                var ptr = (IntPtr)(bytePtr + message.Payload.Offset);
                int r;
                var 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_try_send(NativeHandle, buf, 1, ref address);
                }
                else
                {
                    sockaddr_in6 address = UV.ToStruct6(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                    r = uv_udp_try_send(NativeHandle, buf, 1, ref address);
                }
                return(r);
            }
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #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);
        }
예제 #6
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);
        }
예제 #7
0
 internal static extern int uv_udp_send6_win(IntPtr req, IntPtr handle, WindowsBufferStruct[] bufs, int bufcnt, sockaddr_in6 addr, callback callback);
예제 #8
0
 internal static extern int uv_udp_bind6(IntPtr handle, sockaddr_in6 sockaddr, short flags);
예제 #9
0
 internal extern static int uv_udp_send6_unix(IntPtr req, IntPtr handle, UnixBufferStruct[] bufs, int bufcnt, sockaddr_in6 addr, callback callback);
예제 #10
0
 internal static extern int uv_udp_bind6(IntPtr handle, sockaddr_in6 sockaddr, short flags);
예제 #11
0
파일: Tcp.cs 프로젝트: carlokok/LibuvSharp
 internal static extern int uv_tcp_bind6(IntPtr handle, sockaddr_in6 sockaddr);
예제 #12
0
 internal extern static int uv_udp_send(IntPtr req, IntPtr handle, UnixBufferStruct[] bufs, int nbufs, ref sockaddr_in6 addr, callback callback);
예제 #13
0
 static extern int uv_udp_bind(IntPtr handle, ref sockaddr_in6 sockaddr, uint flags);
예제 #14
0
파일: Udp.cs 프로젝트: txdv/LibuvSharp
 internal extern static int uv_udp_send(IntPtr req, IntPtr handle, uv_buf_t[] bufs, int nbufs, ref sockaddr_in6 addr, callback callback);
예제 #15
0
파일: Udp.cs 프로젝트: txdv/LibuvSharp
 internal extern static int uv_udp_try_send(IntPtr handle, uv_buf_t[] bufs, int nbufs, ref sockaddr_in6 addr);
예제 #16
0
 internal static extern int uv_tcp_connect(IntPtr req, IntPtr handle, ref sockaddr_in6 addr, callback callback);
예제 #17
0
 internal extern static int uv_ip6_addr(string ip, int port, out sockaddr_in6 address);
예제 #18
0
 internal extern static int uv_udp_try_send(IntPtr handle, UnixBufferStruct[] bufs, int nbufs, ref sockaddr_in6 addr);
예제 #19
0
 internal static extern int uv_tcp_bind6(IntPtr handle, sockaddr_in6 sockaddr);
예제 #20
0
		internal extern static int uv_ip6_addr(string ip, int port, out sockaddr_in6 address);
예제 #21
0
파일: Tcp.cs 프로젝트: carlokok/LibuvSharp
 internal static extern int uv_tcp_connect6(IntPtr req, IntPtr handle, sockaddr_in6 addr, callback callback);