Get information from a raw network socket file descriptor. More...
#include <socket.hpp>
Public Member Functions | |
CSocket_basic () | |
Default constructor for an empty basic socket object with invalid socket file descriptor. | |
CSocket_basic (SOCKET a_sfd) | |
Constructor for the socket file descriptor. Before use, it must be load(). | |
Setter | |
void | load () |
Load the raw socket file descriptor specified with the constructor into the object. | |
Getter | |
operator SOCKET () const | |
Get raw socket file descriptor. | |
bool | local_saddr (SSockaddr *a_saddr=nullptr) const |
Get the local socket address the socket is bound to. | |
bool | remote_saddr (SSockaddr *a_saddr=nullptr) const |
Get the remote socket address the socket is connected to. | |
int | socktype () const |
Get the socket type. | |
int | sockerr () const |
Get the error that is given from the socket as option. | |
bool | is_reuse_addr () const |
Get status if reusing address is enabled. | |
Get information from a raw network socket file descriptor.
For general information have a look at socket_module.
This class takes the resources and results as given by the platform (Unix, MacOS, MS Windows). It does not perform any emulations for unification. The behavior can be different on different platforms.
An object of this class does not take ownership of the raw socket file descriptor and will never close it. This is also the reason why you cannot modify the socket and only have getter available (except the setter 'load()' for the raw socket file descriptor itself). But it is helpful to easily get information about an existing raw socket file descriptor. Closing the file descriptor is in the responsibility of the caller who created the socket. If you need to manage a socket you must use CSocket.
Definition at line 129 of file socket.hpp.
UPnPsdk::CSocket_basic::CSocket_basic | ( | ) |
Default constructor for an empty basic socket object with invalid socket file descriptor.
Definition at line 178 of file socket.cpp.
UPnPsdk::CSocket_basic::CSocket_basic | ( | SOCKET | a_sfd | ) |
Constructor for the socket file descriptor. Before use, it must be load().
[in] | a_sfd | Socket file descriptor. |
Definition at line 182 of file socket.cpp.
|
virtual |
Definition at line 188 of file socket.cpp.
void UPnPsdk::CSocket_basic::load | ( | ) |
Load the raw socket file descriptor specified with the constructor into the object.
The socket file descriptor was given with the constructor. This object does not take ownership of the socket file descriptor and will never close it. Closing is in the responsibility of the caller who created the socket. Initializing it again is possible but is only waste of resources. The result is the same as before.
std::runtime_error | Given socket file descriptor is invalid. |
Definition at line 196 of file socket.cpp.
UPnPsdk::CSocket_basic::operator SOCKET | ( | ) | const |
Get raw socket file descriptor.
Definition at line 220 of file socket.cpp.
bool UPnPsdk::CSocket_basic::local_saddr | ( | SSockaddr * | a_saddr = nullptr | ) | const |
Get the local socket address the socket is bound to.
std::runtime_error | system errors as specified. |
[out] | a_saddr | Optional: pointer to a socket address object that will be filled with the address information of a local network adapter that the socket is bound to. If an error is thrown, this socket address object is not modified. If no information is available (the socket is not bound to a local network adapter) an unspecified socket address (":0") is returned, possibly with address family ("[::]:0" or 0.0.0.0:0"). But working with IP-version is not intended. |
Definition at line 231 of file socket.cpp.
bool UPnPsdk::CSocket_basic::remote_saddr | ( | SSockaddr * | a_saddr = nullptr | ) | const |
Get the remote socket address the socket is connected to.
For an example look at CSocket_basic::local_saddr().
std::runtime_error | system errors as specified except "The socket is not connected". |
[out] | a_saddr | Optional: pointer to a socket address object that will be filled with the remote address information. If an error is thrown, this socket address object is not modified. If no information is available (the socket is not connected to a remote peer) an unspecified socket address (":0") is returned, possibly with address family ("[::]:0" or 0.0.0.0:0"). But working with IP-version is not intended. |
Definition at line 287 of file socket.cpp.
int UPnPsdk::CSocket_basic::socktype | ( | ) | const |
Get the socket type.
SOCK_STREAM
or SOCK_DGRAM
. std::runtime_error | if query option fails. |
Definition at line 337 of file socket.cpp.
int UPnPsdk::CSocket_basic::sockerr | ( | ) | const |
Get the error that is given from the socket as option.
This is not a system error from the operating system (with POSIX returned in errno). It is the error that can be queried as option from the socket.
std::runtime_error | if query option fails. |
Definition at line 358 of file socket.cpp.
bool UPnPsdk::CSocket_basic::is_reuse_addr | ( | ) | const |
Get status if reusing address is enabled.
For details to this option have a look at option "reuse address".
std::runtime_error | if query option fails. |
Definition at line 379 of file socket.cpp.