jsocketpp 1.0
A cross-platform C++20 socket library.
Loading...
Searching...
No Matches
SocketInitializer.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "common.hpp"
9#include "SocketException.hpp"
10
11namespace jsocketpp
12{
20{
21 public:
27 {
28 if (InitSockets() != 0)
29 {
30 const int error = GetSocketError();
31 throw SocketException(error, SocketErrorMessage(error));
32 }
33 }
34
40 {
41 if (CleanupSockets() != 0)
42 std::cerr << "Socket cleanup failed: " << SocketErrorMessage(GetSocketError()) << ": " << GetSocketError()
43 << std::endl;
44 }
45
50
55};
56
57} // namespace jsocketpp
Exception class for socket-related errors in jsocketpp.
Represents socket-related errors in the jsocketpp library.
Definition SocketException.hpp:63
SocketInitializer & operator=(const SocketInitializer &rhs)=delete
Deleted copy assignment operator (non-copyable).
SocketInitializer()
Initialize socket system (WSAStartup on Windows).
Definition SocketInitializer.hpp:26
SocketInitializer(const SocketInitializer &rhs)=delete
Deleted copy constructor (non-copyable).
~SocketInitializer() noexcept
Clean up socket system (WSACleanup on Windows).
Definition SocketInitializer.hpp:39
Common platform and utility includes for jsocketpp.
A C++ socket library providing Java-style networking interfaces.
Definition BufferView.hpp:16
int CleanupSockets()
Definition common.hpp:241
std::string SocketErrorMessage(int error, bool gaiStrerror=false)
Convert a socket-related error code to a human-readable message.
Definition common.cpp:5
int GetSocketError()
Definition common.hpp:246
int InitSockets()
Definition common.hpp:235