-
Notifications
You must be signed in to change notification settings - Fork 9
/
SocketErrors.h
129 lines (99 loc) · 3.85 KB
/
SocketErrors.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// This file contains all error-related functions and definitions.
#ifndef SOCKETERRORS_H
#define SOCKETERRORS_H
// ========================================================================
// Include Files
// ========================================================================
#include "SocketTypes.h"
#include <exception>
#include <string>
namespace SocketLib
{
// ========================================================================
// Description: Error codes for the socket library.
// ========================================================================
enum Error
{
// errors that shouldn't happen, so if they do, something is wrong:
ESeriousError,
// these errors are common
ENetworkDown,
ENoSocketsAvailable,
ENoMemory,
EAddressNotAvailable,
EAlreadyConnected,
ENotConnected,
EConnectionRefused,
ENetworkUnreachable,
ENetworkReset,
EHostUnreachable,
EHostDown,
EConnectionAborted,
EConnectionReset,
EOperationWouldBlock,
// DNS errors
EDNSNotFound,
EDNSError,
ENoDNSData,
// These errors are specific errors that should never or rarely occur.
EInProgress,
EInterrupted,
EAccessDenied,
EInvalidParameter,
EAddressFamilyNotSupported,
EProtocolFamilyNotSupported,
EProtocolNotSupported,
EProtocolNotSupportedBySocket,
EOperationNotSupported,
EInvalidSocketType,
EInvalidSocket,
EAddressRequired,
EMessageTooLong,
EBadProtocolOption,
EAddressInUse,
ETimedOut,
EShutDown,
// auxilliary socketlib errors
ESocketLimitReached,
ENotAvailable,
EConnectionClosed
};
// ========================================================================
// Description: This translates error codes from the native platoform
// format into the SocketLib format
// ========================================================================
Error TranslateError( int p_error, bool p_errno );
// ========================================================================
// Description: This function acts as a simple wrapper for retrieving
// socket library errors from errno or h_errno.
// ========================================================================
Error GetError( bool p_errno = true );
// ========================================================================
// Type: Exception
// Purpose: A generic socket exception class that holds an error, and
// an optional text string describing the error in more detail
// ========================================================================
class Exception : public std::exception
{
public:
// ====================================================================
// Function: Exception
// Purpose: To initialize the socket exception with a specific
// error code.
// ====================================================================
Exception( Error p_code );
// ====================================================================
// Function: Error
// Purpose: To retrieve the error code of the socket.
// ====================================================================
Error ErrorCode();
// ====================================================================
// Function: PrintError
// Purpose: Print the error message to a string
// ====================================================================
std::string PrintError();
protected:
Error m_code;
};
}
#endif