net/SocketDescriptor: add method GetIntOption()
This commit is contained in:
parent
85286d74ef
commit
1239e075b8
@ -23,14 +23,7 @@
|
|||||||
int
|
int
|
||||||
SocketDescriptor::GetType() const noexcept
|
SocketDescriptor::GetType() const noexcept
|
||||||
{
|
{
|
||||||
assert(IsDefined());
|
return GetIntOption(SOL_SOCKET, SO_TYPE, -1);
|
||||||
|
|
||||||
int type;
|
|
||||||
socklen_t size = sizeof(type);
|
|
||||||
return getsockopt(fd, SOL_SOCKET, SO_TYPE,
|
|
||||||
(char *)&type, &size) == 0
|
|
||||||
? type
|
|
||||||
: -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -210,6 +203,14 @@ SocketDescriptor::GetOption(int level, int name,
|
|||||||
: 0;
|
: 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
|
#ifdef HAVE_STRUCT_UCRED
|
||||||
|
|
||||||
struct ucred
|
struct ucred
|
||||||
|
@ -188,6 +188,9 @@ public:
|
|||||||
std::size_t GetOption(int level, int name,
|
std::size_t GetOption(int level, int name,
|
||||||
void *value, std::size_t size) const noexcept;
|
void *value, std::size_t size) const noexcept;
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
|
int GetIntOption(int level, int name, int fallback) const noexcept;
|
||||||
|
|
||||||
#ifdef HAVE_STRUCT_UCRED
|
#ifdef HAVE_STRUCT_UCRED
|
||||||
/**
|
/**
|
||||||
* Receive peer credentials (SO_PEERCRED). On error, the pid
|
* Receive peer credentials (SO_PEERCRED). On error, the pid
|
||||||
|
Loading…
Reference in New Issue
Block a user