Skip to content

Commit a12ab30

Browse files
authored
Merge pull request #9414 from SeppoTakalo/ONME-4013
Clarify asynchronous Networkinterface::connect() and disconnect() API
2 parents dbc3c62 + 6c5b845 commit a12ab30

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

features/lwipstack/LWIPInterface.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
503503
if (connected == NSAPI_STATUS_GLOBAL_UP) {
504504
return NSAPI_ERROR_IS_CONNECTED;
505505
} else if (connected == NSAPI_STATUS_CONNECTING) {
506-
return NSAPI_ERROR_ALREADY;
506+
return NSAPI_ERROR_BUSY;
507507
}
508508

509509
connected = NSAPI_STATUS_CONNECTING;
@@ -595,7 +595,6 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
595595
if (!blocking) {
596596
// Done enough - as addresses are acquired, there will be
597597
// connected callbacks.
598-
// XXX shouldn't this be NSAPI_ERROR_IN_PROGRESS if in CONNECTING state?
599598
return NSAPI_ERROR_OK;
600599
}
601600

features/netsocket/NetworkInterface.h

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,39 @@ class NetworkInterface: public DNS {
137137
*/
138138
virtual nsapi_error_t set_dhcp(bool dhcp);
139139

140-
/** Start the interface.
140+
/** Connect to a network.
141141
*
142-
* This blocks until connection is established, but asynchronous operation can be enabled
143-
* by calling NetworkInterface::set_blocking(false).
142+
* This blocks until connection is established, but asynchronous operation can be enabled
143+
* by calling NetworkInterface::set_blocking(false).
144144
*
145-
* In asynchronous mode this starts the connection sequence and returns immediately.
146-
* Status of the connection can then checked from NetworkInterface::get_connection_status()
147-
* or from status callbacks.
145+
* In asynchronous mode this starts the connection sequence and returns immediately.
146+
* Status of the connection can then checked from NetworkInterface::get_connection_status()
147+
* or from status callbacks.
148148
*
149-
* @return NSAPI_ERROR_OK on success, or if asynchronous operation started.
150-
* @return NSAPI_ERROR_ALREADY if asynchronous connect operation already ongoing.
151-
* @return NSAPI_ERROR_IS_CONNECTED if interface is already connected.
152-
* @return negative error code on failure.
149+
* NetworkInterface internally handles reconnections until disconnect() is called.
150+
*
151+
* @return NSAPI_ERROR_OK if connection established in blocking mode.
152+
* @return NSAPI_ERROR_OK if asynchronous operation started.
153+
* @return NSAPI_ERROR_BUSY if asynchronous operation cannot be started.
154+
Implementation guarantees event generation, which can be used as an
155+
trigger to reissue the rejected request.
156+
* @return NSAPI_ERROR_IS_CONNECTED if already connected.
157+
* @return negative error code on failure.
153158
*/
154159
virtual nsapi_error_t connect() = 0;
155160

156-
/** Stop the interface.
161+
/** Disconnect from the network
157162
*
158163
* This blocks until interface is disconnected, unless interface is set to
159164
* asynchronous (non-blocking) mode by calling NetworkInterface::set_blocking(false).
160165
*
161-
* @return NSAPI_ERROR_OK on success, or if asynchronous operation started.
162-
@ @return negative error code on failure.
166+
* @return NSAPI_ERROR_OK on successfully disconnected in blocking mode.
167+
* @return NSAPI_ERROR_OK if asynchronous operation started.
168+
* @return NSAPI_ERROR_BUSY if asynchronous operation cannot be started.
169+
Implementation guarantees event generation, which can be used as an
170+
trigger to reissue the rejected request.
171+
* @return NSAPI_ERROR_NO_CONNECTION if already disconnected.
172+
* @return negative error code on failure.
163173
*/
164174
virtual nsapi_error_t disconnect() = 0;
165175

@@ -253,10 +263,15 @@ class NetworkInterface: public DNS {
253263
*/
254264
virtual nsapi_connection_status_t get_connection_status() const;
255265

256-
/** Set blocking status of connect() which by default should be blocking.
266+
/** Set asynchronous operation of connect() and disconnect() calls.
257267
*
258-
* @param blocking Use true to make connect() blocking.
259-
* @return NSAPI_ERROR_OK on success, negative error code on failure.
268+
* By default, interfaces are in synchronous mode which means that
269+
* connect() or disconnect() blocks until it reach the target state or requested operation fails.
270+
*
271+
* @param blocking Use true to set NetworkInterface in asynchronous mode.
272+
* @return NSAPI_ERROR_OK on success
273+
* @return NSAPI_ERROR_UNSUPPORTED if driver does not support asynchronous mode.
274+
* @return negative error code on failure.
260275
*/
261276
virtual nsapi_error_t set_blocking(bool blocking);
262277

features/netsocket/nsapi_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ enum nsapi_error {
5555
NSAPI_ERROR_CONNECTION_TIMEOUT = -3017, /*!< connection timed out */
5656
NSAPI_ERROR_ADDRESS_IN_USE = -3018, /*!< Address already in use */
5757
NSAPI_ERROR_TIMEOUT = -3019, /*!< operation timed out */
58+
NSAPI_ERROR_BUSY = -3020, /*!< device is busy and cannot accept new operation */
5859
};
5960

6061

0 commit comments

Comments
 (0)