Skip to content

Commit a885cd8

Browse files
committed
net/SocketDescriptor: add Duplicate() method
The the Duplicate() method we inherited from class FileDescriptor returns a UniqueFileDescriptor, but we really want to return a UniqueSocketDescriptor.
1 parent b05dfce commit a885cd8

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/net/SocketDescriptor.cxx

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "StaticSocketAddress.hxx"
77
#include "IPv4Address.hxx"
88
#include "IPv6Address.hxx"
9+
#include "UniqueSocketDescriptor.hxx"
910

1011
#ifdef _WIN32
1112
#include <ws2tcpip.h>
@@ -243,7 +244,15 @@ SocketDescriptor::SetNonBlocking() const noexcept
243244
return ioctlsocket(fd, FIONBIO, &val) == 0;
244245
}
245246

246-
#endif
247+
#else
248+
249+
UniqueSocketDescriptor
250+
SocketDescriptor::Duplicate() const noexcept
251+
{
252+
return UniqueSocketDescriptor{FileDescriptor::Duplicate()};
253+
}
254+
255+
#endif // !_WIN32
247256

248257
bool
249258
SocketDescriptor::SetOption(int level, int name,

src/net/SocketDescriptor.hxx

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class SocketAddress;
2424
class StaticSocketAddress;
2525
class IPv4Address;
2626
class IPv6Address;
27+
class UniqueSocketDescriptor;
2728

2829
/**
2930
* An OO wrapper for a Berkeley or WinSock socket descriptor.
@@ -137,7 +138,10 @@ public:
137138

138139
using FileDescriptor::SetNonBlocking;
139140
using FileDescriptor::SetBlocking;
140-
using FileDescriptor::Duplicate;
141+
142+
[[nodiscard]]
143+
UniqueSocketDescriptor Duplicate() const noexcept;
144+
141145
using FileDescriptor::CheckDuplicate;
142146
using FileDescriptor::Close;
143147
#else

src/net/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ net_dep = declare_dependency(
2323
link_with: net,
2424
dependencies: [
2525
system_dep,
26+
io_dep,
2627
],
2728
)

0 commit comments

Comments
 (0)