public void Connect(IPEndPoint ipEndPoint, Action <Exception?>?callback) { CheckDisposed(); Ensure.ArgumentNotNull(ipEndPoint, "ipEndPoint"); 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); }
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); } }
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); }
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); }
internal static extern int uv_tcp_connect(IntPtr req, IntPtr handle, ref sockaddr_in6 addr, callback callback);
internal static extern int uv_tcp_bind(IntPtr handle, ref sockaddr_in6 sockaddr, uint flags);
internal extern static int uv_udp_send(IntPtr req, IntPtr handle, uv_buf_t[] bufs, int nbufs, ref sockaddr_in6 addr, callback callback);
internal extern static int uv_udp_try_send(IntPtr handle, uv_buf_t[] bufs, int nbufs, ref sockaddr_in6 addr);
private static extern int uv_udp_bind(IntPtr handle, ref sockaddr_in6 sockaddr, uint flags);
internal extern static int uv_ip6_addr(string ip, int port, out sockaddr_in6 address);