Skip to content

Commit 367beb7

Browse files
committed
Handle +UUSOCL URC in GSMUDP and GSMServer
1 parent c2b3d30 commit 367beb7

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

src/GSMServer.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,17 @@ void GSMServer::handleUrc(const String& urc)
240240
} else if (urc.startsWith("+UUSOCL: ")) {
241241
int socket = urc.charAt(urc.length() - 1) - '0';
242242

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;
248251

249-
break;
252+
break;
253+
}
250254
}
251255
}
252256
} else if (urc.startsWith("+UUSORD: ")) {

src/GSMUdp.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ void GSMUDP::stop()
7676

7777
int GSMUDP::beginPacket(IPAddress ip, uint16_t port)
7878
{
79+
if (_socket < 0) {
80+
return 0;
81+
}
82+
7983
_txIp = ip;
8084
_txHost = NULL;
8185
_txPort = port;
@@ -86,6 +90,10 @@ int GSMUDP::beginPacket(IPAddress ip, uint16_t port)
8690

8791
int GSMUDP::beginPacket(const char *host, uint16_t port)
8892
{
93+
if (_socket < 0) {
94+
return 0;
95+
}
96+
8997
_txIp = (uint32_t)0;
9098
_txHost = host;
9199
_txPort = port;
@@ -154,6 +162,10 @@ size_t GSMUDP::write(uint8_t b)
154162

155163
size_t GSMUDP::write(const uint8_t *buffer, size_t size)
156164
{
165+
if (_socket < 0) {
166+
return 0;
167+
}
168+
157169
size_t spaceAvailable = sizeof(_txBuffer) - _txSize;
158170

159171
if (size > spaceAvailable) {
@@ -170,6 +182,10 @@ int GSMUDP::parsePacket()
170182
{
171183
MODEM.poll();
172184

185+
if (_socket < 0) {
186+
return 0;
187+
}
188+
173189
if (!_packetReceived) {
174190
return 0;
175191
}
@@ -239,6 +255,10 @@ int GSMUDP::parsePacket()
239255

240256
int GSMUDP::available()
241257
{
258+
if (_socket < 0) {
259+
return 0;
260+
}
261+
242262
return (_rxIndex - _rxSize);
243263
}
244264

@@ -299,5 +319,14 @@ void GSMUDP::handleUrc(const String& urc)
299319
if (socket == _socket) {
300320
_packetReceived = true;
301321
}
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+
}
302331
}
303332
}

0 commit comments

Comments
 (0)