Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::SocketDescriptor Struct Reference

Low-level OS socket handle. More...

#include <SocketDescriptor.h>

Inheritance diagram for SC::SocketDescriptor:
SC::UniqueHandle< detail::SocketDescriptorDefinition >

Public Member Functions

Result create (SocketFlags::AddressFamily addressFamily, SocketFlags::SocketType socketType=SocketFlags::SocketStream, SocketFlags::ProtocolType protocol=SocketFlags::ProtocolTcp, SocketFlags::BlockingType blocking=SocketFlags::Blocking, SocketFlags::InheritableType inheritable=SocketFlags::NonInheritable)
 Creates a new Socket Descriptor of given family, type, protocol. More...
 
Result isInheritable (bool &value) const
 Check if socket is inheritable by child processes. More...
 
Result setInheritable (bool value)
 Changes the inheritable flag for this socket. More...
 
Result setBlocking (bool value)
 Changes the blocking flag for this socket (if IO reads / writes should be blocking or not) More...
 
Result getAddressFamily (SocketFlags::AddressFamily &addressFamily) const
 Get address family (IPV4 / IPV6) of this socket. More...
 

Detailed Description

Low-level OS socket handle.

It also allow querying inheritability and changing it (and blocking mode) Example (extracted from unit test):

// We are testing only the inheritable because on windows there is no reliable
// way of checking if a non-connected socket is in non-blocking mode
SocketDescriptor socket;
SC_TEST_EXPECT(socket.isValid());
isInheritable = false;
SC_TEST_EXPECT(socket.isInheritable(isInheritable));
SC_TEST_EXPECT(socket.close());
SC_TEST_EXPECT(socket.isValid());
isInheritable = false;
SC_TEST_EXPECT(socket.isInheritable(isInheritable));
SC_TEST_EXPECT(socket.close());
SC_TEST_EXPECT(socket.isValid());
isInheritable = false;
SC_TEST_EXPECT(socket.isInheritable(isInheritable));
SC_TEST_EXPECT(socket.close());
#define SC_TEST_EXPECT(e)
Records a test expectation (eventually aborting or breaking o n failed test)
Definition: Testing.h:113
Result isInheritable(bool &value) const
Check if socket is inheritable by child processes.
@ SocketStream
Sets the socket type as Streaming type (for TCP and others)
Definition: SocketDescriptor.h:92
@ AddressFamilyIPV4
IP Address is IPV4.
Definition: SocketDescriptor.h:85
@ NonInheritable
Socket will not be inherited by child processes.
Definition: SocketDescriptor.h:78
@ Inheritable
Socket will be inherited by child processes.
Definition: SocketDescriptor.h:79
@ NonBlocking
Socket is in non-blocking mode.
Definition: SocketDescriptor.h:71
@ Blocking
Socket is in blocking mode.
Definition: SocketDescriptor.h:72
@ ProtocolTcp
The protocol is TCP.
Definition: SocketDescriptor.h:99

Member Function Documentation

◆ create()

Creates a new Socket Descriptor of given family, type, protocol.

Parameters
addressFamilyAddress family (IPV4 / IPV6)
socketTypeSocket type (Stream or Dgram)
protocolProtocol (TCP or UDP)
blockingIf the socket should be created in blocking mode
inheritableIf the socket should be inheritable by child processes
Returns
Valid Result if a socket with the requested options has been successfully created

◆ getAddressFamily()

Result SC::SocketDescriptor::getAddressFamily ( SocketFlags::AddressFamily addressFamily) const

Get address family (IPV4 / IPV6) of this socket.

Parameters
[out]addressFamilyThe address family of this socket (if Result is valid)
Returns
Valid Result the address family for this socket has been queried successfully

◆ isInheritable()

Result SC::SocketDescriptor::isInheritable ( bool &  value) const

Check if socket is inheritable by child processes.

Parameters
[out]valueif set to true indicates that this socket is inheritable by child processes
Returns
Valid Result if the inheritable status for this socket has been queried successfully

◆ setBlocking()

Result SC::SocketDescriptor::setBlocking ( bool  value)

Changes the blocking flag for this socket (if IO reads / writes should be blocking or not)

Parameters
valuetrue if this socket should be made blocking, false for non-blocking
Returns
Valid Result if it has been possible changing the blocking status of this socket

◆ setInheritable()

Result SC::SocketDescriptor::setInheritable ( bool  value)

Changes the inheritable flag for this socket.

Parameters
valuetrue if this socket should be made inheritable, false for non-inheritable
Returns
Valid Result if it has been possible changing the inheritable status of this socket

The documentation for this struct was generated from the following file: