File tree Expand file tree Collapse file tree 2 files changed +39
-6
lines changed Expand file tree Collapse file tree 2 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -240,13 +240,17 @@ void GSMServer::handleUrc(const String& urc)
240
240
} else if (urc.startsWith (" +UUSOCL: " )) {
241
241
int socket = urc.charAt (urc.length () - 1 ) - ' 0' ;
242
242
243
- for (int i = 0 ; i < MAX_CHILD_SOCKETS; i++) {
244
- if (_childSockets[i].socket == socket) {
245
- _childSockets[i].socket = -1 ;
246
- _childSockets[i].accepted = false ;
247
- _childSockets[i].available = 0 ;
243
+ if (socket == _socket) {
244
+ _socket = -1 ;
245
+ } else {
246
+ for (int i = 0 ; i < MAX_CHILD_SOCKETS; i++) {
247
+ if (_childSockets[i].socket == socket) {
248
+ _childSockets[i].socket = -1 ;
249
+ _childSockets[i].accepted = false ;
250
+ _childSockets[i].available = 0 ;
248
251
249
- break ;
252
+ break ;
253
+ }
250
254
}
251
255
}
252
256
} else if (urc.startsWith (" +UUSORD: " )) {
Original file line number Diff line number Diff line change @@ -76,6 +76,10 @@ void GSMUDP::stop()
76
76
77
77
int GSMUDP::beginPacket (IPAddress ip, uint16_t port)
78
78
{
79
+ if (_socket < 0 ) {
80
+ return 0 ;
81
+ }
82
+
79
83
_txIp = ip;
80
84
_txHost = NULL ;
81
85
_txPort = port;
@@ -86,6 +90,10 @@ int GSMUDP::beginPacket(IPAddress ip, uint16_t port)
86
90
87
91
int GSMUDP::beginPacket (const char *host, uint16_t port)
88
92
{
93
+ if (_socket < 0 ) {
94
+ return 0 ;
95
+ }
96
+
89
97
_txIp = (uint32_t )0 ;
90
98
_txHost = host;
91
99
_txPort = port;
@@ -154,6 +162,10 @@ size_t GSMUDP::write(uint8_t b)
154
162
155
163
size_t GSMUDP::write (const uint8_t *buffer, size_t size)
156
164
{
165
+ if (_socket < 0 ) {
166
+ return 0 ;
167
+ }
168
+
157
169
size_t spaceAvailable = sizeof (_txBuffer) - _txSize;
158
170
159
171
if (size > spaceAvailable) {
@@ -170,6 +182,10 @@ int GSMUDP::parsePacket()
170
182
{
171
183
MODEM.poll ();
172
184
185
+ if (_socket < 0 ) {
186
+ return 0 ;
187
+ }
188
+
173
189
if (!_packetReceived) {
174
190
return 0 ;
175
191
}
@@ -239,6 +255,10 @@ int GSMUDP::parsePacket()
239
255
240
256
int GSMUDP::available ()
241
257
{
258
+ if (_socket < 0 ) {
259
+ return 0 ;
260
+ }
261
+
242
262
return (_rxIndex - _rxSize);
243
263
}
244
264
@@ -299,5 +319,14 @@ void GSMUDP::handleUrc(const String& urc)
299
319
if (socket == _socket) {
300
320
_packetReceived = true ;
301
321
}
322
+ } else if (urc.startsWith (" +UUSOCL: " )) {
323
+ int socket = urc.charAt (urc.length () - 1 ) - ' 0' ;
324
+
325
+ if (socket == _socket) {
326
+ // this socket closed
327
+ _socket = -1 ;
328
+ _rxIndex = 0 ;
329
+ _rxSize = 0 ;
330
+ }
302
331
}
303
332
}
You can’t perform that action at this time.
0 commit comments