Skip to content

Commit 2ac04c5

Browse files
author
Ari Parkkila
committed
Cellular: Change CellularNonIPSocket to singleton
1 parent 413d421 commit 2ac04c5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

features/netsocket/cellular/CellularNonIPSocket.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121

2222
using namespace mbed;
2323

24+
ControlPlane_netif *CellularNonIPSocket::_cp_netif;
25+
2426
CellularNonIPSocket::CellularNonIPSocket()
2527
: _timeout(osWaitForever),
2628
_readers(0), _writers(0), _pending(0),
27-
_cp_netif(NULL),
2829
_opened(false)
2930
{}
3031

@@ -46,10 +47,15 @@ nsapi_error_t CellularNonIPSocket::open(ControlPlane_netif *cp_netif)
4647
{
4748
_lock.lock();
4849

49-
if (_cp_netif != NULL || cp_netif == NULL) {
50+
if (cp_netif == NULL || _opened) {
5051
_lock.unlock();
5152
return NSAPI_ERROR_PARAMETER;
5253
}
54+
55+
if (_cp_netif) {
56+
_lock.unlock();
57+
return NSAPI_ERROR_NO_SOCKET;
58+
}
5359
_cp_netif = cp_netif;
5460

5561
_event = callback(this, &CellularNonIPSocket::event);
@@ -92,6 +98,9 @@ nsapi_error_t CellularNonIPSocket::close()
9298

9399
nsapi_size_or_error_t CellularNonIPSocket::send(const void *data, nsapi_size_t size)
94100
{
101+
if (!data) {
102+
return NSAPI_ERROR_PARAMETER;
103+
}
95104
_lock.lock();
96105
nsapi_size_or_error_t ret;
97106

@@ -164,7 +173,6 @@ nsapi_size_or_error_t CellularNonIPSocket::recv(void *buffer, nsapi_size_t size)
164173

165174
if (flag & osFlagsError) {
166175
// Timeout break
167-
ret = NSAPI_ERROR_WOULD_BLOCK;
168176
break;
169177
}
170178
}

features/netsocket/cellular/CellularNonIPSocket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class CellularNonIPSocket : public Socket {
150150
static const int WRITE_FLAG = 0x2u;
151151
static const int FINISHED_FLAG = 0x3u;
152152

153-
ControlPlane_netif *_cp_netif;
153+
static ControlPlane_netif *_cp_netif; // there can be only one Non-IP socket
154154
bool _opened;
155155
};
156156

0 commit comments

Comments
 (0)