Skip to content

Commit 6c5b845

Browse files
author
Seppo Takalo
committed
Clarify asyncronous Networkinterface::connect() and disconnect() API
This is slight API change, as a new return code is introduced. Intention is to properly support asyncronous drivers that might not be able to get new operation into execution, therefore they need to return BUSY.
1 parent 1a8844e commit 6c5b845

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
@@ -133,29 +133,39 @@ class NetworkInterface: public DNS {
133133
*/
134134
virtual nsapi_error_t set_dhcp(bool dhcp);
135135

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

152-
/** Stop the interface.
157+
/** Disconnect from the network
153158
*
154159
* This blocks until interface is disconnected, unless interface is set to
155160
* asynchronous (non-blocking) mode by calling NetworkInterface::set_blocking(false).
156161
*
157-
* @return NSAPI_ERROR_OK on success, or if asynchronous operation started.
158-
@ @return negative error code on failure.
162+
* @return NSAPI_ERROR_OK on successfully disconnected in blocking mode.
163+
* @return NSAPI_ERROR_OK if asynchronous operation started.
164+
* @return NSAPI_ERROR_BUSY if asynchronous operation cannot be started.
165+
Implementation guarantees event generation, which can be used as an
166+
trigger to reissue the rejected request.
167+
* @return NSAPI_ERROR_NO_CONNECTION if already disconnected.
168+
* @return negative error code on failure.
159169
*/
160170
virtual nsapi_error_t disconnect() = 0;
161171

@@ -249,10 +259,15 @@ class NetworkInterface: public DNS {
249259
*/
250260
virtual nsapi_connection_status_t get_connection_status() const;
251261

252-
/** Set blocking status of connect() which by default should be blocking.
262+
/** Set asynchronous operation of connect() and disconnect() calls.
253263
*
254-
* @param blocking Use true to make connect() blocking.
255-
* @return NSAPI_ERROR_OK on success, negative error code on failure.
264+
* By default, interfaces are in synchronous mode which means that
265+
* connect() or disconnect() blocks until it reach the target state or requested operation fails.
266+
*
267+
* @param blocking Use true to set NetworkInterface in asynchronous mode.
268+
* @return NSAPI_ERROR_OK on success
269+
* @return NSAPI_ERROR_UNSUPPORTED if driver does not support asynchronous mode.
270+
* @return negative error code on failure.
256271
*/
257272
virtual nsapi_error_t set_blocking(bool blocking);
258273

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)