private unsafe void tcp_bind_windows_extras(UvTcpHandle handle) { const int SIO_LOOPBACK_FAST_PATH = -1744830448; // IOC_IN | IOC_WS2 | 16; const int WSAEOPNOTSUPP = 10000 + 45; // (WSABASEERR+45) const int SOCKET_ERROR = -1; var socket = IntPtr.Zero; Check(_uv_fileno(handle, ref socket)); // Enable loopback fast-path for lower latency for localhost comms, like HttpPlatformHandler fronting // http://blogs.technet.com/b/wincat/archive/2012/12/05/fast-tcp-loopback-performance-and-low-latency-with-windows-server-2012-tcp-loopback-fast-path.aspx // https://github.com/libuv/libuv/issues/489 var optionValue = 1; uint dwBytes = 0u; var result = NativeMethods.WSAIoctl(socket, SIO_LOOPBACK_FAST_PATH, &optionValue, sizeof(int), null, 0, out dwBytes, IntPtr.Zero, IntPtr.Zero); if (result == SOCKET_ERROR) { var errorId = NativeMethods.WSAGetLastError(); if (errorId == WSAEOPNOTSUPP) { // This system is not >= Windows Server 2012, and the call is not supported. } else { Check(errorId); } } }
public void tcp_bind(UvTcpHandle handle, ref SockAddr addr, int flags) { handle.Validate(); Check(_uv_tcp_bind(handle, ref addr, flags)); if (PlatformApis.IsWindows) { tcp_bind_windows_extras(handle); } }
public static extern int uv_tcp_getpeername(UvTcpHandle handle,out SockAddr name,ref int namelen);
public static extern int uv_tcp_nodelay(UvTcpHandle handle,int enable);
public static extern int uv_tcp_open(UvTcpHandle handle,IntPtr hSocket);
public static extern int uv_tcp_bind(UvTcpHandle handle,ref SockAddr addr,int flags);
public static extern int uv_tcp_init(UvLoopHandle loop,UvTcpHandle handle);
public void tcp_getpeername(UvTcpHandle handle, out SockAddr addr, ref int namelen) { handle.Validate(); ThrowIfErrored(_uv_tcp_getpeername(handle, out addr, ref namelen)); }
public void tcp_nodelay(UvTcpHandle handle, bool enable) { handle.Validate(); ThrowIfErrored(_uv_tcp_nodelay(handle, enable ? 1 : 0)); }
public void tcp_open(UvTcpHandle handle, IntPtr hSocket) { handle.Validate(); ThrowIfErrored(_uv_tcp_open(handle, hSocket)); }
public void tcp_bind(UvTcpHandle handle, ref SockAddr addr, int flags) { handle.Validate(); ThrowIfErrored(_uv_tcp_bind(handle, ref addr, flags)); }
public void tcp_init(UvLoopHandle loop, UvTcpHandle handle) { loop.Validate(); handle.Validate(); ThrowIfErrored(_uv_tcp_init(loop, handle)); }
public void tcp_getsockname(UvTcpHandle handle, out SockAddr addr, ref int namelen) { handle.Validate(); Check(_uv_tcp_getsockname(handle, out addr, ref namelen)); }
public void tcp_nodelay(UvTcpHandle handle, bool enable) { handle.Validate(); Check(_uv_tcp_nodelay(handle, enable ? 1 : 0)); }
public void tcp_open(UvTcpHandle handle, IntPtr hSocket) { handle.Validate(); Check(_uv_tcp_open(handle, hSocket)); }
public void tcp_init(UvLoopHandle loop, UvTcpHandle handle) { loop.Validate(); handle.Validate(); Check(_uv_tcp_init(loop, handle)); }