@@ -69,7 +69,7 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
69
69
70
70
if ((_at.get_last_error () == NSAPI_ERROR_OK) && err) {
71
71
if (err == BG96_SOCKET_BIND_FAIL) {
72
- socket->created = false ;
72
+ socket->id = - 1 ;
73
73
_at.unlock ();
74
74
return NSAPI_ERROR_PARAMETER;
75
75
}
@@ -106,7 +106,7 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
106
106
_at.unlock ();
107
107
108
108
if ((ret_val == NSAPI_ERROR_OK) && (modem_connect_id == request_connect_id)) {
109
- socket->created = true ;
109
+ socket->id = request_connect_id ;
110
110
socket->remoteAddress = address;
111
111
socket->connected = true ;
112
112
return NSAPI_ERROR_OK;
@@ -182,10 +182,14 @@ void QUECTEL_BG96_CellularStack::handle_open_socket_response(int &modem_connect_
182
182
nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl (CellularSocket *socket)
183
183
{
184
184
int modem_connect_id = -1 ;
185
- int request_connect_id = socket->id ;
186
185
int remote_port = 0 ;
187
186
int err = -1 ;
188
187
188
+ int request_connect_id = find_socket_index (socket);
189
+ // assert here as its a programming error if the socket container doesn't contain
190
+ // specified handle
191
+ MBED_ASSERT (request_connect_id != -1 );
192
+
189
193
if (socket->proto == NSAPI_UDP && !socket->connected ) {
190
194
_at.cmd_start (" AT+QIOPEN=" );
191
195
_at.write_int (_cid);
@@ -201,7 +205,7 @@ nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *soc
201
205
202
206
if ((_at.get_last_error () == NSAPI_ERROR_OK) && err) {
203
207
if (err == BG96_SOCKET_BIND_FAIL) {
204
- socket->created = false ;
208
+ socket->id = - 1 ;
205
209
return NSAPI_ERROR_PARAMETER;
206
210
}
207
211
_at.cmd_start (" AT+QICLOSE=" );
@@ -233,7 +237,7 @@ nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *soc
233
237
234
238
if ((_at.get_last_error () == NSAPI_ERROR_OK) && err) {
235
239
if (err == BG96_SOCKET_BIND_FAIL) {
236
- socket->created = false ;
240
+ socket->id = - 1 ;
237
241
return NSAPI_ERROR_PARAMETER;
238
242
}
239
243
_at.cmd_start (" AT+QICLOSE=" );
@@ -261,7 +265,9 @@ nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *soc
261
265
262
266
nsapi_error_t ret_val = _at.get_last_error ();
263
267
264
- socket->created = ((ret_val == NSAPI_ERROR_OK) && (modem_connect_id == request_connect_id));
268
+ if (ret_val == NSAPI_ERROR_OK && (modem_connect_id == request_connect_id)) {
269
+ socket->id = request_connect_id;
270
+ }
265
271
266
272
return ret_val;
267
273
}
0 commit comments