@@ -118,7 +118,7 @@ bool UBLOX_AT_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
118
118
119
119
nsapi_error_t UBLOX_AT_CellularStack::create_socket_impl (CellularSocket *socket)
120
120
{
121
- int sock_id = 0 ;
121
+ int sock_id = SOCKET_UNUSED ;
122
122
123
123
_at.lock ();
124
124
if (socket->proto == NSAPI_UDP) {
@@ -146,13 +146,12 @@ nsapi_error_t UBLOX_AT_CellularStack::create_socket_impl(CellularSocket *socket)
146
146
// Check for duplicate socket id delivered by modem
147
147
for (int i = 0 ; i < UBLOX_MAX_SOCKET; i++) {
148
148
CellularSocket *sock = _socket[i];
149
- if (sock && sock-> created && sock->id == sock_id) {
149
+ if (sock && sock != socket && sock->id == sock_id) {
150
150
return NSAPI_ERROR_NO_SOCKET;
151
151
}
152
152
}
153
153
154
154
socket->id = sock_id;
155
- socket->created = true ;
156
155
157
156
return NSAPI_ERROR_OK;
158
157
}
@@ -162,7 +161,7 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_connect(nsapi_socket_t handle, cons
162
161
CellularSocket *socket = (CellularSocket *)handle;
163
162
164
163
if (socket) {
165
- if (! socket->created ) {
164
+ if (socket->id != SOCKET_UNUSED ) {
166
165
nsapi_error_t err = create_socket_impl (socket);
167
166
if (err != NSAPI_ERROR_OK) {
168
167
return err;
@@ -192,6 +191,8 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_connect(nsapi_socket_t handle, cons
192
191
nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl (CellularSocket *socket, const SocketAddress &address,
193
192
const void *data, nsapi_size_t size)
194
193
{
194
+ MBED_ASSERT (socket->id != -1 );
195
+
195
196
int sent_len = 0 ;
196
197
pollfh fhs;
197
198
fhs.fh = _at.get_file_handle ();
@@ -261,6 +262,8 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
261
262
nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl (CellularSocket *socket, SocketAddress *address,
262
263
void *buffer, nsapi_size_t size)
263
264
{
265
+ MBED_ASSERT (socket->id != -1 );
266
+
264
267
nsapi_size_or_error_t nsapi_error_size = NSAPI_ERROR_DEVICE_ERROR;
265
268
bool success = true ;
266
269
nsapi_size_t read_blk;
@@ -430,7 +433,6 @@ void UBLOX_AT_CellularStack::clear_socket(CellularSocket *socket)
430
433
socket->pending_bytes = 0 ;
431
434
socket->_cb = NULL ;
432
435
socket->_data = NULL ;
433
- socket->created = false ;
434
436
}
435
437
}
436
438
0 commit comments