UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches

Class for portable handling of network socket errors. More...

#include <socket.hpp>

Public Member Functions

 CSocketErr (const CSocketErr &)=delete
 
CSocketErroperator= (const CSocketErr &)=delete
 
 operator const int & ()
 Get error number.
 
void catch_error ()
 Catch error for later use.
 
std::string error_str () const
 Get human readable error description of the catched error.
 

Detailed Description

Class for portable handling of network socket errors.

// Usage e.g.:
CSocketErr serrObj;
int ret = some_function_1();
if (ret != 0) {
serrObj.catch_error();
int errid = serrObj;
std::cout << "Error " << errid << ": "
<< serrObj.error_str() << "\n";
}
ret = some_function_2();
if (ret != 0) {
serrObj.catch_error();
std::cout << "Error " << static_cast<int>(serrObj) << ": "
<< serrObj.error_str() << "\n";
}
Class for portable handling of network socket errors.
Definition socket.hpp:537
void catch_error()
Catch error for later use.
Definition socket.cpp:609
std::string error_str() const
Get human readable error description of the catched error.
Definition socket.cpp:618

There is a compatibility problem with Winsock2 on the Microsoft Windows platform that does not support detailed error information given in the global variable 'errno' that is used by POSIX. Instead it returns them with calling 'WSAGetLastError()'. This class encapsulates differences so there is no need to always check the platform to get the error information.

This class is optimized for frequent short-term use. It's a simple class without inheritence and virtual methods.

Definition at line 537 of file socket.hpp.

Member Function Documentation

◆ operator const int &()

UPnPsdk::CSocketErr::operator const int & ( )

Get error number.

Definition at line 602 of file socket.cpp.

◆ catch_error()

void UPnPsdk::CSocketErr::catch_error ( )

Catch error for later use.

Definition at line 609 of file socket.cpp.

+ Here is the caller graph for this function:

◆ error_str()

std::string UPnPsdk::CSocketErr::error_str ( ) const

Get human readable error description of the catched error.

Definition at line 618 of file socket.cpp.

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: