net: add new method Sock::Bind() that wraps bind()

This will help to increase `Sock` usage and make more code mockable.
This commit is contained in:
Vasil Dimov 2021-04-13 16:31:04 +02:00
parent 7164e00e1b
commit 3ad7de225e
No known key found for this signature in database
GPG key ID: 54DF06F64B55CBBF
6 changed files with 36 additions and 2 deletions

View file

@ -2396,8 +2396,7 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
#endif
}
if (::bind(sock->Get(), (struct sockaddr*)&sockaddr, len) == SOCKET_ERROR)
{
if (sock->Bind(reinterpret_cast<struct sockaddr*>(&sockaddr), len) == SOCKET_ERROR) {
int nErr = WSAGetLastError();
if (nErr == WSAEADDRINUSE)
strError = strprintf(_("Unable to bind to %s on this computer. %s is probably already running."), addrBind.ToString(), PACKAGE_NAME);