@@ -135,34 +135,50 @@ namespace Aws
135
135
aws_mem_release (callbackData->allocator , reinterpret_cast <void *>(callbackData));
136
136
}
137
137
138
- MqttConnection::MqttConnection (MqttClient* client,
139
- const char * hostName, uint16_t port,
140
- const Io::SocketOptions& socketOptions,
141
- Io::TlsConnectionOptions&& tlsConnOptions) noexcept :
142
- m_owningClient (client),
143
- m_lastError (AWS_ERROR_SUCCESS),
144
- m_connectionState (ConnectionState::Init)
138
+ void MqttConnection::s_connectionInit (MqttConnection* self,
139
+ const char * hostName, uint16_t port, const Io::SocketOptions& socketOptions,
140
+ Io::TlsConnectionOptions* tlsConnOptions)
145
141
{
146
142
aws_mqtt_client_connection_callbacks callbacks;
147
143
AWS_ZERO_STRUCT (callbacks);
148
- callbacks.user_data = this ;
144
+ callbacks.user_data = self ;
149
145
callbacks.on_connack = s_onConnAck;
150
146
callbacks.on_connection_failed = s_onConnectionFailed;
151
147
callbacks.on_disconnect = s_onDisconnect;
152
148
153
149
ByteBuf hostNameBuf = aws_byte_buf_from_c_str (hostName);
154
150
ByteCursor hostNameCur = aws_byte_cursor_from_buf (&hostNameBuf);
155
151
156
- m_underlyingConnection =
157
- aws_mqtt_client_connection_new (&m_owningClient->m_client , callbacks,
158
- &hostNameCur, port,
159
- (Io::SocketOptions*)&socketOptions, &tlsConnOptions);
152
+ self->m_underlyingConnection = aws_mqtt_client_connection_new (&self->m_owningClient ->m_client ,
153
+ callbacks, &hostNameCur, port,
154
+ const_cast <Io::SocketOptions*>(&socketOptions), tlsConnOptions);
160
155
161
- if (!m_underlyingConnection)
156
+ if (!self-> m_underlyingConnection )
162
157
{
163
- m_connectionState = ConnectionState::Error;
164
- m_lastError = aws_last_error ();
165
- }
158
+ self->m_connectionState = ConnectionState::Error;
159
+ self->m_lastError = aws_last_error ();
160
+ }
161
+ }
162
+
163
+ MqttConnection::MqttConnection (MqttClient* client,
164
+ const char * hostName, uint16_t port,
165
+ const Io::SocketOptions& socketOptions,
166
+ Io::TlsConnectionOptions&& tlsConnOptions) noexcept :
167
+ m_owningClient (client),
168
+ m_lastError (AWS_ERROR_SUCCESS),
169
+ m_connectionState (ConnectionState::Init)
170
+ {
171
+ s_connectionInit (this , hostName, port, socketOptions, &tlsConnOptions);
172
+ }
173
+
174
+ MqttConnection::MqttConnection (MqttClient* client,
175
+ const char * hostName, uint16_t port,
176
+ const Io::SocketOptions& socketOptions) noexcept :
177
+ m_owningClient (client),
178
+ m_lastError (AWS_ERROR_SUCCESS),
179
+ m_connectionState (ConnectionState::Init)
180
+ {
181
+ s_connectionInit (this , hostName, port, socketOptions, nullptr );
166
182
}
167
183
168
184
MqttConnection::~MqttConnection ()
@@ -495,6 +511,13 @@ namespace Aws
495
511
{
496
512
return MqttConnection (this , hostName, port, socketOptions, std::move (tlsConnOptions));
497
513
}
514
+
515
+ MqttConnection MqttClient::NewConnection (const char * hostName, uint16_t port,
516
+ const Io::SocketOptions& socketOptions) noexcept
517
+
518
+ {
519
+ return MqttConnection (this , hostName, port, socketOptions);
520
+ }
498
521
}
499
522
}
500
523
}
0 commit comments