@@ -117,55 +117,6 @@ bool UBLOX_AT_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
117
117
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
118
118
}
119
119
120
- nsapi_error_t UBLOX_AT_CellularStack::socket_open (nsapi_socket_t *handle, nsapi_protocol_t proto)
121
- {
122
- if (!is_protocol_supported (proto) || !handle) {
123
- return NSAPI_ERROR_UNSUPPORTED;
124
- }
125
-
126
- int max_socket_count = get_max_socket_count ();
127
-
128
- if (!_socket) {
129
- _socket = new CellularSocket*[max_socket_count];
130
- if (!_socket) {
131
- return NSAPI_ERROR_NO_SOCKET;
132
- }
133
- _socket_count = max_socket_count;
134
- for (int i = 0 ; i < max_socket_count; i++) {
135
- _socket[i] = 0 ;
136
- }
137
- }
138
-
139
- int index = -1 ;
140
- for (int i = 0 ; i < max_socket_count; i++) {
141
- if (!_socket[i]) {
142
- index = i;
143
- break ;
144
- }
145
- }
146
-
147
- if (index == -1 ) {
148
- return NSAPI_ERROR_NO_SOCKET;
149
- }
150
-
151
- // create local socket structure, socket on modem is created when app calls sendto/recvfrom
152
- _socket[index] = new CellularSocket;
153
- CellularSocket *psock;
154
- psock = _socket[index];
155
- memset (psock, 0 , sizeof (CellularSocket));
156
- SocketAddress addr (0 , get_dynamic_ip_port ());
157
- psock->id = index;
158
- psock->localAddress = addr;
159
- psock->proto = proto;
160
- nsapi_error_t err = create_socket_impl (psock);
161
-
162
- if (err == NSAPI_ERROR_OK) {
163
- *handle = psock;
164
- }
165
-
166
- return err;
167
- }
168
-
169
120
nsapi_error_t UBLOX_AT_CellularStack::create_socket_impl (CellularSocket *socket)
170
121
{
171
122
int sock_id = 0 ;
@@ -212,8 +163,8 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_connect(nsapi_socket_t handle, cons
212
163
{
213
164
CellularSocket *socket = (CellularSocket *)handle;
214
165
215
- if (!socket) {
216
- return NSAPI_ERROR_DEVICE_ERROR ;
166
+ if (!socket-> created ) {
167
+ create_socket_impl (socket) ;
217
168
}
218
169
219
170
_at.lock ();
0 commit comments