net/UniqueSocketDescriptor: use AdoptTag in the constructors that adopt ownership
This makes it a little bit harder to use the ownershop-adopting constructors accidently.
This commit is contained in:

committed by
Max Kellermann

parent
131263cbe3
commit
765a6a2f20
@ -49,7 +49,7 @@ listen_systemd_activation(ClientListener &listener)
|
|||||||
|
|
||||||
for (int i = SD_LISTEN_FDS_START, end = SD_LISTEN_FDS_START + n;
|
for (int i = SD_LISTEN_FDS_START, end = SD_LISTEN_FDS_START + n;
|
||||||
i != end; ++i)
|
i != end; ++i)
|
||||||
listener.AddFD(UniqueSocketDescriptor(i));
|
listener.AddFD(UniqueSocketDescriptor{AdoptTag{}, i});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ inline void
|
|||||||
ServerSocket::OneServerSocket::Accept() noexcept
|
ServerSocket::OneServerSocket::Accept() noexcept
|
||||||
{
|
{
|
||||||
StaticSocketAddress peer_address;
|
StaticSocketAddress peer_address;
|
||||||
UniqueSocketDescriptor peer_fd(event.GetSocket().AcceptNonBlock(peer_address));
|
UniqueSocketDescriptor peer_fd{AdoptTag{}, event.GetSocket().AcceptNonBlock(peer_address)};
|
||||||
if (!peer_fd.IsDefined()) {
|
if (!peer_fd.IsDefined()) {
|
||||||
const SocketErrorMessage msg;
|
const SocketErrorMessage msg;
|
||||||
FmtError(server_socket_domain,
|
FmtError(server_socket_domain,
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SocketDescriptor.hxx"
|
#include "SocketDescriptor.hxx"
|
||||||
|
#include "util/TagStructs.hxx"
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include "io/UniqueFileDescriptor.hxx"
|
#include "io/UniqueFileDescriptor.hxx"
|
||||||
@ -21,17 +22,17 @@ public:
|
|||||||
UniqueSocketDescriptor() noexcept
|
UniqueSocketDescriptor() noexcept
|
||||||
:SocketDescriptor(SocketDescriptor::Undefined()) {}
|
:SocketDescriptor(SocketDescriptor::Undefined()) {}
|
||||||
|
|
||||||
explicit UniqueSocketDescriptor(SocketDescriptor _fd) noexcept
|
explicit UniqueSocketDescriptor(AdoptTag, SocketDescriptor _fd) noexcept
|
||||||
:SocketDescriptor(_fd) {}
|
:SocketDescriptor(_fd) {}
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
explicit UniqueSocketDescriptor(FileDescriptor _fd) noexcept
|
explicit UniqueSocketDescriptor(AdoptTag, FileDescriptor _fd) noexcept
|
||||||
:SocketDescriptor(_fd) {}
|
:SocketDescriptor(_fd) {}
|
||||||
|
|
||||||
explicit UniqueSocketDescriptor(UniqueFileDescriptor &&_fd) noexcept
|
explicit UniqueSocketDescriptor(UniqueFileDescriptor &&_fd) noexcept
|
||||||
:SocketDescriptor(_fd.Release()) {}
|
:SocketDescriptor(_fd.Release()) {}
|
||||||
#endif // !_WIN32
|
#endif // !_WIN32
|
||||||
|
|
||||||
explicit UniqueSocketDescriptor(int _fd) noexcept
|
explicit UniqueSocketDescriptor(AdoptTag, int _fd) noexcept
|
||||||
:SocketDescriptor(_fd) {}
|
:SocketDescriptor(_fd) {}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -75,14 +76,14 @@ public:
|
|||||||
* @return an "undefined" instance on error
|
* @return an "undefined" instance on error
|
||||||
*/
|
*/
|
||||||
UniqueSocketDescriptor AcceptNonBlock() const noexcept {
|
UniqueSocketDescriptor AcceptNonBlock() const noexcept {
|
||||||
return UniqueSocketDescriptor(SocketDescriptor::AcceptNonBlock());
|
return UniqueSocketDescriptor{AdoptTag{}, SocketDescriptor::AcceptNonBlock()};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return an "undefined" instance on error
|
* @return an "undefined" instance on error
|
||||||
*/
|
*/
|
||||||
UniqueSocketDescriptor AcceptNonBlock(StaticSocketAddress &address) const noexcept {
|
UniqueSocketDescriptor AcceptNonBlock(StaticSocketAddress &address) const noexcept {
|
||||||
return UniqueSocketDescriptor(SocketDescriptor::AcceptNonBlock(address));
|
return UniqueSocketDescriptor{AdoptTag{}, SocketDescriptor::AcceptNonBlock(address)};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
Reference in New Issue
Block a user