static sockaddr_in6 CreateSockaddrIp6(string ip, int port) { int result = UVInterop.uv_ip6_addr(ip, port, out sockaddr_in6 address); UVException.ThrowIfError(result); return(address); }
static sockaddr_in CreateSockaddr(string ip, int port) { sockaddr_in address; int result = UVInterop.uv_ip4_addr(ip, port, out address); UVException.ThrowIfError(result); return(address); }
static void Bind(TcpListener listener, string ipAddress, int port, bool ip6 = false, bool dualstack = false) { if (ip6) { sockaddr_in6 address = CreateSockaddrIp6(ipAddress.ToString(), port); UVException.ThrowIfError(UVInterop.uv_tcp_bind(listener.Handle, ref address, (uint)(dualstack ? 0 : 1))); } else { sockaddr_in address = CreateSockaddr(ipAddress.ToString(), port); UVException.ThrowIfError(UVInterop.uv_tcp_bind(listener.Handle, ref address, 0)); } }
static void OnNotified(IntPtr handle, int status) { var listener = As <UVListener <TStream> >(handle); var stream = listener.CreateStream(); var connection = stream as TStream; try { UVException.ThrowIfError(UVInterop.uv_accept(listener.Handle, connection.Handle)); } catch (Exception) { stream.Dispose(); connection.Dispose(); throw; } if (listener.ConnectionAccepted != null) { listener.ConnectionAccepted(connection); } }
public void Listen(int backlog) { UVInterop.uv_listen(Handle, backlog, Notified); }
void SetKeepAlive(bool value, int delay) { UVInterop.uv_tcp_keepalive(Handle, value ? 1 : 0, delay); }
void SetNoDelay(bool value) { UVInterop.uv_tcp_nodelay(Handle, value ? 1 : 0); }
internal Tcp(UVLoop loop) : base(loop, HandleType.UV_TCP) { UVInterop.uv_tcp_init(loop.Handle, Handle); }
public TcpListener(string ipAddress, int port, UVLoop loop) : base(loop, HandleType.UV_TCP) { UVException.ThrowIfError(UVInterop.uv_tcp_init(Loop.Handle, Handle)); Bind(this, ipAddress, port); }