mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
net: add RAII socket and use it instead of bare SOCKET
Introduce a class to manage the lifetime of a socket - when the object that contains the socket goes out of scope, the underlying socket will be closed. In addition, the new `Sock` class has a `Send()`, `Recv()` and `Wait()` methods that can be overridden by unit tests to mock the socket operations. The `Wait()` method also hides the `#ifdef USE_POLL poll() #else select() #endif` technique from higher level code.
This commit is contained in:
@@ -123,3 +123,8 @@ struct timeval MillisToTimeval(int64_t nTimeout)
|
||||
timeout.tv_usec = (nTimeout % 1000) * 1000;
|
||||
return timeout;
|
||||
}
|
||||
|
||||
struct timeval MillisToTimeval(std::chrono::milliseconds ms)
|
||||
{
|
||||
return MillisToTimeval(count_milliseconds(ms));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user