net/SocketDescriptor: add method GetIntOption()

This commit is contained in:
Max Kellermann
2023-11-22 11:59:10 +01:00
committed by Max Kellermann
parent 85286d74ef
commit 1239e075b8
2 changed files with 12 additions and 8 deletions

View File

@@ -23,14 +23,7 @@
int
SocketDescriptor::GetType() const noexcept
{
assert(IsDefined());
int type;
socklen_t size = sizeof(type);
return getsockopt(fd, SOL_SOCKET, SO_TYPE,
(char *)&type, &size) == 0
? type
: -1;
return GetIntOption(SOL_SOCKET, SO_TYPE, -1);
}
bool
@@ -210,6 +203,14 @@ SocketDescriptor::GetOption(int level, int name,
: 0;
}
int
SocketDescriptor::GetIntOption(int level, int name, int fallback) const noexcept
{
int value = fallback;
GetOption(level, name, &value, sizeof(value));
return value;
}
#ifdef HAVE_STRUCT_UCRED
struct ucred