@@ -51,15 +51,18 @@ ESP8266Interface::ESP8266Interface()
51
51
_conn_stat(NSAPI_STATUS_DISCONNECTED),
52
52
_conn_stat_cb(NULL )
53
53
{
54
- memset (_ids, 0 , sizeof (_ids));
55
54
memset (_cbs, 0 , sizeof (_cbs));
56
55
memset (ap_ssid, 0 , sizeof (ap_ssid));
57
56
memset (ap_pass, 0 , sizeof (ap_pass));
58
- memset (_local_ports, 0 , sizeof (_local_ports));
59
57
60
58
_esp.sigio (this , &ESP8266Interface::event);
61
59
_esp.set_timeout ();
62
60
_esp.attach (this , &ESP8266Interface::update_conn_state_cb);
61
+
62
+ for (int i= 0 ; i < ESP8266_SOCKET_COUNT; i++) {
63
+ _sock_i[i].open = false ;
64
+ _sock_i[i].sport = -1 ;
65
+ }
63
66
}
64
67
#endif
65
68
@@ -72,15 +75,18 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
72
75
_conn_stat(NSAPI_STATUS_DISCONNECTED),
73
76
_conn_stat_cb(NULL )
74
77
{
75
- memset (_ids, 0 , sizeof (_ids));
76
78
memset (_cbs, 0 , sizeof (_cbs));
77
79
memset (ap_ssid, 0 , sizeof (ap_ssid));
78
80
memset (ap_pass, 0 , sizeof (ap_pass));
79
- memset (_local_ports, 0 , sizeof (_local_ports));
80
81
81
82
_esp.sigio (this , &ESP8266Interface::event);
82
83
_esp.set_timeout ();
83
84
_esp.attach (this , &ESP8266Interface::update_conn_state_cb);
85
+
86
+ for (int i= 0 ; i < ESP8266_SOCKET_COUNT; i++) {
87
+ _sock_i[i].open = false ;
88
+ _sock_i[i].sport = -1 ;
89
+ }
84
90
}
85
91
86
92
int ESP8266Interface::connect (const char *ssid, const char *pass, nsapi_security_t security,
@@ -324,9 +330,9 @@ int ESP8266Interface::socket_open(void **handle, nsapi_protocol_t proto)
324
330
int id = -1 ;
325
331
326
332
for (int i = 0 ; i < ESP8266_SOCKET_COUNT; i++) {
327
- if (!_ids [i]) {
333
+ if (!_sock_i [i]. open ) {
328
334
id = i;
329
- _ids [i] = true ;
335
+ _sock_i [i]. open = true ;
330
336
break ;
331
337
}
332
338
}
@@ -362,8 +368,8 @@ int ESP8266Interface::socket_close(void *handle)
362
368
}
363
369
364
370
socket->connected = false ;
365
- _ids [socket->id ] = false ;
366
- _local_ports [socket->id ] = 0 ;
371
+ _sock_i [socket->id ]. open = false ;
372
+ _sock_i [socket->id ]. sport = - 1 ;
367
373
delete socket;
368
374
return err;
369
375
}
@@ -382,13 +388,13 @@ int ESP8266Interface::socket_bind(void *handle, const SocketAddress &address)
382
388
}
383
389
384
390
for (int id = 0 ; id < ESP8266_SOCKET_COUNT; id++) {
385
- if (_local_ports [id] == address.get_port () && id != socket->id ) { // Port already reserved by another socket
391
+ if (_sock_i [id]. sport == address.get_port () && id != socket->id ) { // Port already reserved by another socket
386
392
return NSAPI_ERROR_PARAMETER;
387
393
} else if (id == socket->id && socket->connected ) {
388
394
return NSAPI_ERROR_PARAMETER;
389
395
}
390
396
}
391
- _local_ports [socket->id ] = address.get_port ();
397
+ _sock_i [socket->id ]. sport = address.get_port ();
392
398
return 0 ;
393
399
}
394
400
@@ -410,7 +416,7 @@ int ESP8266Interface::socket_connect(void *handle, const SocketAddress &addr)
410
416
}
411
417
412
418
if (socket->proto == NSAPI_UDP) {
413
- ret = _esp.open_udp (socket->id , addr.get_ip_address (), addr.get_port (), _local_ports [socket->id ]);
419
+ ret = _esp.open_udp (socket->id , addr.get_ip_address (), addr.get_port (), _sock_i [socket->id ]. sport );
414
420
} else {
415
421
ret = _esp.open_tcp (socket->id , addr.get_ip_address (), addr.get_port (), socket->keepalive );
416
422
}
0 commit comments