mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-06 18:53:21 +01:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user