The socket module contains all classes and free functions to manage network sockets. More...
Classes | |
class | UPnPsdk::CSocket_basic |
Get information from a raw network socket file descriptor. More... | |
class | UPnPsdk::CSocket |
Manage all aspects of a network socket. More... | |
class | UPnPsdk::CSocketErr |
Class for portable handling of network socket errors. More... | |
The socket module contains all classes and free functions to manage network sockets.
This module mainly consists of the CSocket class but also provides free functions to manage a socket. The problem is that socket handling isn't very good portable. There is different behavior on the supported platforms Unix, MacOS and Microsoft Windows. The CSocket class atempts to be consistent portable on all three platforms by using common behavior or by emulating missing functions on a platform.
The class encapsulates and manages one raw socket file descriptor. The file descriptor of a valid socket object cannot be changed but the object with its immutable file descriptor can be moved and assigned to another socket object. Copying a socket object isn't supported because having two objects with the same file descriptor may be very error prone in particular with multithreading. Effort has been taken to do not cache any socket information outside the socket file descriptor. Nearly all socket informations are direct set and get to/from the operating system with the file descriptor. The socket file descriptor is always valid except on an empty socket object.
An empty socket object can be instantiated with the default constructor, e.g. CSocket sockObj;
. It is a valid object and should be destructed. When moving a socket object, the left over source object is also empty. An empty socket object has an INVALID_SOCKET
defined and no valid content. It throws an exception if using most of its Setter and Getter. Moving and assigning it is possible. You can test for an empty socket by looking for an INVALID_SOCKET
, e.g.
This SDK handles network connections IP Version - Independent so that a protocoll family (PF_INET6, PF_INET, PF_UNIX) or address family (AF_INET6, AF_INET, AF_UNIX) is never used on the SDKs Application Programming Interface. IP Version is managed by the operating system.
Only SOCK_STREAM
and SOCK_DGRAM
is supported. Any other type throws an exception.
I don't set the option to immediately reuse an address and I always set the option SO_EXCLUSIVEADDRUSE
on Microsoft Windows. For more details of this have a look at Socket option "reuse address".