net/SocketDescriptor: add GetType(), IsStream()
This commit is contained in:
parent
b5c569cd30
commit
50c7337965
@ -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
|
||||
|
@ -82,6 +82,20 @@ public:
|
||||
using FileDescriptor::IsValid;
|
||||
using FileDescriptor::IsSocket;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Determine the socket type, i.e. SOCK_STREAM, SOCK_DGRAM or
|
||||
* SOCK_SEQPACKET. Returns -1 on error.
|
||||
*/
|
||||
gcc_pure
|
||||
int GetType() const noexcept;
|
||||
|
||||
/**
|
||||
* Is this a stream socket?
|
||||
*/
|
||||
gcc_pure
|
||||
bool IsStream() const noexcept;
|
||||
|
||||
using FileDescriptor::Get;
|
||||
using FileDescriptor::Set;
|
||||
using FileDescriptor::Steal;
|
||||
|
Loading…
Reference in New Issue
Block a user