netbase: extend CreateSock() to support creating arbitrary sockets

Allow the callers of `CreateSock()` to pass all 3 arguments to the
`socket(2)` syscall. This makes it possible to create sockets of
any domain/type/protocol.
This commit is contained in:
Vasil Dimov
2024-05-30 13:38:26 +02:00
parent 0b94fb8720
commit 1245d1388b
6 changed files with 33 additions and 33 deletions

View File

@@ -262,16 +262,18 @@ CService LookupNumeric(const std::string& name, uint16_t portDefault = 0, DNSLoo
CSubNet LookupSubNet(const std::string& subnet_str);
/**
* Create a TCP or UNIX socket in the given address family.
* @param[in] address_family to use for the socket.
* Create a real socket from the operating system.
* @param[in] domain Communications domain, first argument to the socket(2) syscall.
* @param[in] type Type of the socket, second argument to the socket(2) syscall.
* @param[in] protocol The particular protocol to be used with the socket, third argument to the socket(2) syscall.
* @return pointer to the created Sock object or unique_ptr that owns nothing in case of failure
*/
std::unique_ptr<Sock> CreateSockOS(sa_family_t address_family);
std::unique_ptr<Sock> CreateSockOS(int domain, int type, int protocol);
/**
* Socket factory. Defaults to `CreateSockOS()`, but can be overridden by unit tests.
*/
extern std::function<std::unique_ptr<Sock>(const sa_family_t&)> CreateSock;
extern std::function<std::unique_ptr<Sock>(int, int, int)> CreateSock;
/**
* Create a socket and try to connect to the specified service.