@@ -50,6 +50,9 @@ class Socket {
5050 * Closes any open connection and deallocates any memory associated
5151 * with the socket. Called from destructor if socket is not closed.
5252 *
53+ * If this socket was allocated by an accept() call, then calling this will also delete
54+ * the socket object itself.
55+ *
5356 * @return NSAPI_ERROR_OK on success.
5457 * Negative subclass-dependent error code on failure.
5558 */
@@ -307,20 +310,22 @@ class Socket {
307310 */
308311 virtual nsapi_error_t getsockopt (int level, int optname, void *optval, unsigned *optlen) = 0;
309312
310- /* * Accepts a connection on a socket.
313+ /* *
314+ * @brief Waits for a client to try to connect to this socket, then returns a socket for the new connection.
315+ *
316+ * On error, returns nullptr and sets the error code parameter (if provided).
311317 *
312- * The server socket must be bound and set to listen for connections.
313- * On a new connection, returns connected network socket to call close()
314- * that deallocates the resources. Referencing a returned pointer after a close()
315- * call is not allowed and leads to undefined behavior.
318+ * Note that if a socket is returned, you must eventually call close() on it to release its resources.
319+ * Calling close() will also delete the socket object, no separate \c delete is required.
320+ * Referencing the returned socket after a close() call is not allowed and leads to undefined behavior.
316321 *
317- * By default, accept blocks until incoming connection occurs. If socket is set to
318- * non-blocking or times out, error is set to NSAPI_ERROR_WOULD_BLOCK .
322+ * By default, this function blocks until an incoming connection occurs. If socket is set to
323+ * non-blocking or times out, an \c NSAPI_ERROR_WOULD_BLOCK error is returned .
319324 *
320- * @param error Pointer to storage of the error value or NULL .
321- * @return Pointer to a socket.
325+ * @param error If you wish to check the error code, pass an error code pointer here .
326+ * @return Pointer to a socket, or nullptr on error
322327 */
323- virtual Socket *accept (nsapi_error_t *error = NULL ) = 0;
328+ virtual Socket *accept (nsapi_error_t *error = nullptr ) = 0;
324329
325330 /* * Listen for incoming connections.
326331 *
0 commit comments