net/SocketDescriptor: add GetType(), IsStream()

This commit is contained in:
Max Kellermann
2018-08-20 16:06:58 +02:00
parent b5c569cd30
commit 50c7337965
2 changed files with 33 additions and 0 deletions

View File

@@ -44,6 +44,25 @@
#include <errno.h>
#include <string.h>
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;
}
bool
SocketDescriptor::IsStream() const noexcept
{
return GetType() == SOCK_STREAM;
}
#ifdef _WIN32
void