OpenJPH
Open-source implementation of JPEG2000 Part-15
|
A small wrapper for some Winsock2 functionality. More...
#include <ojph_sockets.h>
Public Member Functions | |
socket_manager () | |
default constructor | |
~socket_manager () | |
default constructor | |
socket | create_socket (int domain, int type, int protocol) |
Abstructs socket creation. | |
int | get_last_error () |
Abstructs get last error or errno. | |
std::string | get_error_message (int errnum) |
Abstructs obtaining a textual message for an errnum. | |
std::string | get_last_error_message () |
Abstructs obtaining a textual message for GetLastError/errno. | |
Static Public Member Functions | |
static ui32 | get_addr (const sockaddr_in &addr) |
Abstractly obtains the 32-bit IPv4 address integer. | |
Static Private Attributes | |
static int | ojph_socket_manager_counter = 0 |
A small wrapper for some Winsock2 functionality.
This is useful for windows, as it initializes and destroys WinSock2 library. It keeps a count of how many times the constructor is called, reducing the count whenever the destructor is called. When the count reaches zero, the library is destroyed – Windows only.
It also allows the creation of a socket, access to the last error in a portable way, and the translation of an error into a text message.
Definition at line 145 of file ojph_sockets.h.
ojph::net::socket_manager::socket_manager | ( | ) |
default constructor
This function initializes the Winsock2 stack in windows; it also increments the static member that keeps count of how many times this object is used.
Definition at line 107 of file ojph_sockets.cpp.
References get_last_error_message(), OJPH_ERROR, and ojph_socket_manager_counter.
ojph::net::socket_manager::~socket_manager | ( | ) |
default constructor
This function cleans up the Winsock2 stack in windows when the static member that keeps count of how many times this object is used reaches zero.
Definition at line 124 of file ojph_sockets.cpp.
References ojph_socket_manager_counter.
socket ojph::net::socket_manager::create_socket | ( | int | domain, |
int | type, | ||
int | protocol ) |
Abstructs socket creation.
This function takes the same parameters as the conventional socket() function
domain | the same as in conventional socket() function |
type | the same as in conventional socket() function |
protocol | the same as in conventional socket() function |
Definition at line 137 of file ojph_sockets.cpp.
Referenced by main().
|
static |
Abstractly obtains the 32-bit IPv4 address integer.
This function obtains a 32-bit integer that represents the IPv4 address in abstrct way (working both in Windows and Linux). This is really an independent function, but it is convenient to put it here.
Definition at line 192 of file ojph_sockets.cpp.
Referenced by main().
std::string ojph::net::socket_manager::get_error_message | ( | int | errnum | ) |
Abstructs obtaining a textual message for an errnum.
This function abstracts obtaining a textual message for an errnum
errnum | the error number |
Definition at line 154 of file ojph_sockets.cpp.
References OJPH_ERROR.
Referenced by get_last_error_message(), and main().
int ojph::net::socket_manager::get_last_error | ( | ) |
Abstructs get last error or errno.
This function abstracts Windows GetLastError or Linux errno
Definition at line 144 of file ojph_sockets.cpp.
Referenced by get_last_error_message(), and main().
std::string ojph::net::socket_manager::get_last_error_message | ( | ) |
Abstructs obtaining a textual message for GetLastError/errno.
This function combines get_error_message() and get_last_error(). This function effectively calls get_last_error() and uses the returned error number to obtain a string by calling get_error_message(errnum).
Definition at line 185 of file ojph_sockets.cpp.
References get_error_message(), and get_last_error().
Referenced by main(), and socket_manager().
|
staticprivate |
Definition at line 228 of file ojph_sockets.h.
Referenced by socket_manager(), and ~socket_manager().