/// <summary> /// Open a new UNIX socket on the given file path /// </summary> /// <param name="endpointType">Type of this HTTP endpoint</param> /// <param name="ns">Namespace of this HTTP endpoint</param> /// <param name="endpointPath">Path of this HTTP endpoint</param> /// <param name="socketPath">Path to the UNIX socket file</param> /// <param name="backlog">Number of simultaneously pending connections</param> /// <exception cref="IOException">Socket could not be opened</exception> public HttpEndpointUnixSocket(HttpEndpointType endpointType, string ns, string endpointPath, string socketPath, int backlog = DefaultBacklog) { // Set up information about this HTTP endpoint EndpointType = endpointType; Namespace = ns; EndpointPath = endpointPath; SocketPath = socketPath; // Clean up socket path again in case of unclean exit File.Delete(socketPath); // Create a new UNIX socket and start listening try { UnixDomainSocketEndPoint endPoint = new UnixDomainSocketEndPoint(socketPath); _unixSocket.Bind(endPoint); _unixSocket.Listen(backlog); AcceptConnections(); } catch { _unixSocket.Close(); throw; } }
/// <summary> /// Add a new third-party HTTP endpoint in the format /machine/{ns}/{path} /// </summary> /// <param name="endpointType">HTTP request type</param> /// <param name="ns">Namespace of the plugin</param> /// <param name="path">Endpoint path</param> /// <param name="backlog">Number of simultaneously pending connections</param> /// <param name="cancellationToken">Optional cancellation token</param> /// <returns>Wrapper around the UNIX socket for accepting HTTP endpoint requests</returns> /// <exception cref="ArgumentException">Endpoint namespace is reserved</exception> /// <exception cref="InvalidOperationException">Endpoint is already in use</exception> /// <exception cref="IOException">UNIX socket could not be opened</exception> /// <exception cref="OperationCanceledException">Operation has been cancelled</exception> /// <exception cref="SocketException">Command could not be processed</exception> public async Task <HttpEndpointUnixSocket> AddHttpEndpoint(HttpEndpointType endpointType, string ns, string path, int backlog = HttpEndpointUnixSocket.DefaultBacklog, CancellationToken cancellationToken = default) { string socketPath = await PerformCommand <string>(new AddHttpEndpoint { EndpointType = endpointType, Namespace = ns, Path = path }, cancellationToken); return(new HttpEndpointUnixSocket(endpointType, ns, path, socketPath, backlog)); }
/// <summary> /// Remove an existing HTTP endpoint /// </summary> /// <param name="endpointType">Type of the endpoint to remove</param> /// <param name="ns">Namespace of the endpoint to remove</param> /// <param name="path">Endpoint to remove</param> /// <param name="cancellationToken">Optional cancellation token</param> /// <returns>True if the endpoint could be removed</returns> /// <exception cref="OperationCanceledException">Operation has been cancelled</exception> /// <exception cref="SocketException">Command could not be processed</exception> public Task <bool> RemoveHttpEndpoint(HttpEndpointType endpointType, string ns, string path, CancellationToken cancellationToken = default) { return(PerformCommand <bool>(new RemoveHttpEndpoint { EndpointType = endpointType, Namespace = ns, Path = path }, cancellationToken)); }