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); }
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); } }
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); }
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 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); }
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); }
internal static extern int uv_udp_send6_win(IntPtr req, IntPtr handle, WindowsBufferStruct[] bufs, int bufcnt, sockaddr_in6 addr, callback callback);
internal static extern int uv_udp_bind6(IntPtr handle, sockaddr_in6 sockaddr, short flags);
internal extern static int uv_udp_send6_unix(IntPtr req, IntPtr handle, UnixBufferStruct[] bufs, int bufcnt, sockaddr_in6 addr, callback callback);
internal static extern int uv_tcp_bind6(IntPtr handle, sockaddr_in6 sockaddr);
internal extern static int uv_udp_send(IntPtr req, IntPtr handle, UnixBufferStruct[] bufs, int nbufs, ref sockaddr_in6 addr, callback callback);
static extern int uv_udp_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);
internal static extern int uv_tcp_connect(IntPtr req, IntPtr handle, ref sockaddr_in6 addr, callback callback);
internal extern static int uv_ip6_addr(string ip, int port, out sockaddr_in6 address);
internal extern static int uv_udp_try_send(IntPtr handle, UnixBufferStruct[] bufs, int nbufs, ref sockaddr_in6 addr);
internal static extern int uv_tcp_connect6(IntPtr req, IntPtr handle, sockaddr_in6 addr, callback callback);