OpenJPH Open-source implementation of JPEG2000 Part-15

Loading...
Searching...
No Matches
ojph::net::socket_manager Class Reference

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

## Detailed Description

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.

## Constructor & Destructor Documentation

## ◆ socket_manager()

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.

## ◆ ~socket_manager()

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.

## Member Function Documentation

## ◆ create_socket()

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

Parameters

  domain | the same as in conventional socket() function
  type | the same as in conventional socket() function
  protocol | the same as in conventional socket() function

Returns
  returns an abstraction of socket

Definition at line 137 of file ojph_sockets.cpp.

Referenced by main().

## ◆ get_addr()

ui32 ojph::net::socket_manager::get_addr | ( | const sockaddr_in & | addr | ) |
| 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.

Returns
  returns an integer holding IPv4 address

Definition at line 192 of file ojph_sockets.cpp.

Referenced by main().

## ◆ get_error_message()

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

Parameters

  errnum | the error number

Returns
  a string holding a textual message for the error number

Definition at line 154 of file ojph_sockets.cpp.

References OJPH_ERROR.

Referenced by get_last_error_message(), and main().

## ◆ get_last_error()

int ojph::net::socket_manager::get_last_error | ( |  | ) |

Abstructs get last error or errno.

This function abstracts Windows GetLastError or Linux errno

Returns
  returns a number representing the error

Definition at line 144 of file ojph_sockets.cpp.

Referenced by get_last_error_message(), and main().

## ◆ get_last_error_message()

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).

Returns
  a string holding a textual message for the error number

Definition at line 185 of file ojph_sockets.cpp.

References get_error_message(), and get_last_error().

Referenced by main(), and socket_manager().

## Member Data Documentation

## ◆ ojph_socket_manager_counter

int ojph::net::socket_manager::ojph_socket_manager_counter = 0
| static private

Definition at line 228 of file ojph_sockets.h.

Referenced by socket_manager(), and ~socket_manager().

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

- /build/openjph/src/OpenJPH/src/apps/common/ojph_sockets.h
- /build/openjph/src/OpenJPH/src/apps/others/ojph_sockets.cpp