net/SocketDescriptor: add method GetProtocol()

This commit is contained in:
Max Kellermann 2023-11-22 12:05:52 +01:00 committed by Max Kellermann
parent 1239e075b8
commit 60033f3eb4
2 changed files with 19 additions and 0 deletions

View File

@ -32,6 +32,16 @@ SocketDescriptor::IsStream() const noexcept
return GetType() == SOCK_STREAM;
}
#ifndef _WIN32
int
SocketDescriptor::GetProtocol() const noexcept
{
return GetIntOption(SOL_SOCKET, SO_PROTOCOL, -1);
}
#endif // !_WIN32
#ifdef _WIN32
void

View File

@ -101,6 +101,15 @@ public:
[[gnu::pure]]
bool IsStream() const noexcept;
#ifndef _WIN32
/**
* Determine the socket protocol (SO_PROTOCOL),
* e.g. IPPROTO_SCTP. Returns -1 on error.
*/
[[gnu::pure]]
int GetProtocol() const noexcept;
#endif // !_WIN32
static constexpr SocketDescriptor Undefined() noexcept {
#ifdef _WIN32
return SocketDescriptor{INVALID_SOCKET};