@@ -144,224 +144,14 @@ inline std::ostream& operator<<(std::ostream& os, const error& err) {
144
144
145
145
} // end namespace client
146
146
147
-
148
- namespace connection {
149
-
150
- /* *
151
- * \brief Defines error codes related to MQTT client connection.
152
- *
153
- * \details Encapsulates errors encountered during the process of establishing a connection.
154
- */
155
- enum class error : int {
156
- /* * Connection has been successfully established */
157
- success = 0 ,
158
-
159
- /* * An error occured during TLS handshake */
160
- tls_handshake_error = 1 ,
161
-
162
- /* * An error occured during WebSocket handshake */
163
- websocket_handshake_error = 2 ,
164
-
165
- // CONNACK
166
- /* * The Server does not wish to reveal the reason for the failure */
167
- unspecified_error = 128 ,
168
-
169
- /* * Data within the CONNECT packet could not be correctly parsed */
170
- malformed_packet = 129 ,
171
-
172
- /* * Data in the CONNECT packet does not conform to this specification */
173
- protocol_error = 130 ,
174
-
175
- /* * The CONNECT is valid but is not accepted by this Server */
176
- implementation_specific_error = 131 ,
177
-
178
- /* * The Server does not support the version of the MQTT protocol requested by the Client */
179
- unsupported_protocol_version = 132 ,
180
-
181
- /* * The Client Identifier is a valid string but is not allowed by the Server */
182
- client_identifier_not_valid = 133 ,
183
-
184
- /* * The Server does not accept the User Name or Password specified by the Client */
185
- bad_username_or_password = 134 ,
186
-
187
- /* * The Client is not authorized to connect */
188
- not_authorized = 135 ,
189
-
190
- /* * The MQTT Server is not available */
191
- server_unavailable = 136 ,
192
-
193
- /* * The Server is busy, try again later */
194
- server_busy = 137 ,
195
-
196
- /* * This Client has been banned by administrative action */
197
- banned = 138 ,
198
-
199
- /* * The authentication method is not supported or does not match the one currently in use. */
200
- bad_authentication_method = 140 ,
201
-
202
- /* * The Will Topic Name is not malformed, but is not accepted by this Server */
203
- topic_name_invalid = 144 ,
204
-
205
- /* * The CONNECT packet exceeded the maximum permissible size */
206
- packet_too_large = 149 ,
207
-
208
- /* * An implementation or administrative imposed limit has been exceeded */
209
- quota_exceeded = 151 ,
210
-
211
- /* * The Will Payload does not match the specified Payload Format Indicator */
212
- payload_format_invalid = 153 ,
213
-
214
- /* * The Server does not support retained messages, and Will Retain was set to 1 */
215
- retain_not_supported = 154 ,
216
-
217
- /* * The Server does not support the QoS set in Will QoS */
218
- qos_not_supported = 155 ,
219
-
220
- /* * The Client should temporarily use another server */
221
- use_another_server = 156 ,
222
-
223
- /* * The Client should permanently use another server */
224
- server_moved = 157 ,
225
-
226
- /* * The connection rate limit has been exceeded */
227
- connection_rate_exceeded = 159
228
- };
229
-
230
- inline std::string connection_error_to_string (error err) {
231
- switch (err) {
232
- case error::success:
233
- return " Connection has been successfully established" ;
234
- case error::tls_handshake_error:
235
- return " Connection failed: An error occured during TLS handshake" ;
236
- case error::websocket_handshake_error:
237
- return " Connection failed: An error occured during WebSocket handshake" ;
238
- case error::unspecified_error:
239
- return " Connection failed: The Server does not wish to reveal "
240
- " the reason for the failure or none of the codes apply" ;
241
- case error::malformed_packet:
242
- return " Connection failed: Data within the CONNECT packet "
243
- " could not be correctly parsed" ;
244
- case error::protocol_error:
245
- return " Connection failed: Data in the CONNECT packet does"
246
- " not conform to this specification" ;
247
- case error::implementation_specific_error:
248
- return " Connection failed : The CONNECT is valid but "
249
- " is not accepted by this Server" ;
250
- case error::unsupported_protocol_version:
251
- return " Connection failed: The Server does not support the "
252
- " version of the MQTT protocol requested by the Client" ;
253
- case error::client_identifier_not_valid:
254
- return " Connection failed: The Client Identifier is a valid "
255
- " string but is not allowed by the Server" ;
256
- case error::bad_username_or_password:
257
- return " Connection failed: The Server does not accept the User Name "
258
- " or Password specified by the Client" ;
259
- case error::not_authorized:
260
- return " Connection failed: The Client is not authorized to connect" ;
261
- case error::server_unavailable:
262
- return " Connection failed: The MQTT Server is not available" ;
263
- case error::server_busy:
264
- return " Connection failed: The Server is busy, try again later" ;
265
- case error::banned:
266
- return " Connection failed: This Client has been banned "
267
- " by administrative action, contact the server administrator" ;
268
- case error::bad_authentication_method:
269
- return " Connection failed: The authentication method is not supported "
270
- " or does not match the authentication method currently in use" ;
271
- case error::topic_name_invalid:
272
- return " Connection failed: The Will Topic Name is not malformed, "
273
- " but is not accepted by this Server" ;
274
- case error::packet_too_large:
275
- return " Connection failed: The CONNECT packet exceeded the maximum "
276
- " permissible size" ;
277
- case error::quota_exceeded:
278
- return " Connection failed: An implementation or administrative "
279
- " imposed limit has been exceeded" ;
280
- case error::payload_format_invalid:
281
- return " Connection failed: The Will Payload does not match "
282
- " the specified Payload Format Indicator" ;
283
- case error::retain_not_supported:
284
- return " Connection failed: The Server does not support "
285
- " retained messages, and Will Retain was set to 1" ;
286
- case error::qos_not_supported:
287
- return " Connection failed: The Server does not support "
288
- " the QoS set in Will QoS" ;
289
- case error::use_another_server:
290
- return " Connection failed: The Client should temporarily "
291
- " use another server" ;
292
- case error::server_moved:
293
- return " Connection failed: The Client should permanently "
294
- " use another server" ;
295
- case error::connection_rate_exceeded:
296
- return " Connection failed: The connection rate limit "
297
- " has been exceeded" ;
298
- default :
299
- return " Unknown connection error" ;
300
- }
301
- }
302
-
303
- struct connection_ec_category : public boost ::system::error_category {
304
- const char * name () const noexcept override { return " mqtt_connection_error" ; }
305
- std::string message (int ev) const noexcept override {
306
- return connection_error_to_string (static_cast <error>(ev));
307
- }
308
- };
309
-
310
- // / Returns the error category associated with \ref connection::error.
311
- inline const connection_ec_category& get_error_code_category () {
312
- static connection_ec_category cat;
313
- return cat;
314
- }
315
-
316
- // / Creates an \ref error_code from a \ref connection::error.
317
- inline boost::system::error_code make_error_code (error r) {
318
- return { static_cast <int >(r), get_error_code_category () };
319
- }
320
-
321
- inline std::ostream& operator <<(std::ostream& os, const error& err) {
322
- os << get_error_code_category ().name () << " :" << static_cast <int >(err);
323
- return os;
324
- }
325
-
326
- } // end namespace connection
327
-
328
147
} // end namespace async_mqtt5
329
148
330
149
namespace boost ::system {
331
150
332
151
template <>
333
152
struct is_error_code_enum <async_mqtt5::client::error> : std::true_type {};
334
153
335
- template <>
336
- struct is_error_code_enum <async_mqtt5::connection::error> : std::true_type {};
337
-
338
154
} // end namespace boost::system
339
155
340
- namespace async_mqtt5 {
341
-
342
- inline bool is_not_recoverable (boost::system::error_code ec) {
343
- using namespace connection ;
344
- return ec == boost::asio::error::no_recovery ||
345
- ec == error::tls_handshake_error ||
346
- ec == error::websocket_handshake_error ||
347
- ec == error::malformed_packet ||
348
- ec == error::implementation_specific_error ||
349
- ec == error::unsupported_protocol_version ||
350
- ec == error::client_identifier_not_valid ||
351
- ec == error::bad_username_or_password ||
352
- ec == error::not_authorized ||
353
- ec == error::banned ||
354
- ec == error::bad_authentication_method ||
355
- ec == error::topic_name_invalid ||
356
- ec == error::packet_too_large ||
357
- ec == error::quota_exceeded ||
358
- ec == error::payload_format_invalid ||
359
- ec == error::retain_not_supported ||
360
- ec == error::qos_not_supported ||
361
- ec == error::use_another_server ||
362
- ec == error::server_moved;
363
- }
364
-
365
- } // end namespace async_mqtt5
366
156
367
157
#endif // !ASYNC_MQTT5_ERROR_HPP
0 commit comments