public void Connect( UvTcpHandle socket, IPEndPoint endpoint, Action <UvConnectRequest, int, Exception, object> callback, object state) { _callback = callback; _state = state; SockAddr addr; var addressText = endpoint.Address.ToString(); Exception error1; _uv.ip4_addr(addressText, endpoint.Port, out addr, out error1); if (error1 != null) { Exception error2; _uv.ip6_addr(addressText, endpoint.Port, out addr, out error2); if (error2 != null) { throw error1; } } Pin(); Libuv.tcp_connect(this, socket, ref addr, _uv_connect_cb); }
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; ThrowIfErrored(_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 { ThrowIfErrored(errorId); } } }
public void tcp_bind(UvTcpHandle handle, ref SockAddr addr, int flags) { handle.Validate(); ThrowIfErrored(_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 void uv_tcp_connect(UvConnectRequest req,UvTcpHandle handle,ref SockAddr addr,uv_connect_cb cb);
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_connect(UvConnectRequest req, UvTcpHandle handle, ref SockAddr addr, uv_connect_cb cb) { req.Validate(); handle.Validate(); _uv_tcp_connect(req, handle, ref addr, cb); }
public void tcp_init(UvLoopHandle loop, UvTcpHandle handle) { loop.Validate(); handle.Validate(); ThrowIfErrored(_uv_tcp_init(loop, handle)); }