Skip to content

Commit b33f8f8

Browse files
Document Socket API functions return values.
Describe the return values with as much detail as possible, to let user only check the relevant return codes, instead of all nsapi_error_t. Refer to underlying APIs wherever possible.
1 parent df79609 commit b33f8f8

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

features/netsocket/TCPSocket.h

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ class TCPSocket : public InternetSocket {
7777
*
7878
* @param host Hostname of the remote host
7979
* @param port Port of the remote host
80-
* @return 0 on success, negative error code on failure
80+
* @retval NSAPI_ERROR_OK on success
81+
* @retval NSAPI_ERROR_IN_PROGRESS if the operation is ongoing
82+
* @retval NSAPI_ERROR_NO_SOCKET if the socket has not been allocated
83+
* @retval NSAPI_ERROR_DNS_FAILURE if the DNS address of host could not be resolved
84+
* @retval NSAPI_ERROR_IS_CONNECTED if the connection is already established
85+
* @retval int Other negative error codes for stack-related failures.
86+
* See NetworkStack::socket_connect().
8187
*/
8288
nsapi_error_t connect(const char *host, uint16_t port);
8389

@@ -87,7 +93,13 @@ class TCPSocket : public InternetSocket {
8793
* indicated address.
8894
*
8995
* @param address The SocketAddress of the remote host
90-
* @return 0 on success, negative error code on failure
96+
* @retval NSAPI_ERROR_OK on success
97+
* @retval NSAPI_ERROR_IN_PROGRESS if the operation is ongoing
98+
* @retval NSAPI_ERROR_NO_SOCKET if the socket has not been allocated
99+
* @retval NSAPI_ERROR_DNS_FAILURE if the DNS address of host could not be resolved
100+
* @retval NSAPI_ERROR_IS_CONNECTED if the connection is already established
101+
* @retval int Other negative error codes for stack-related failures.
102+
* See NetworkStack::socket_connect().
91103
*/
92104
virtual nsapi_error_t connect(const SocketAddress &address);
93105

@@ -102,8 +114,12 @@ class TCPSocket : public InternetSocket {
102114
*
103115
* @param data Buffer of data to send to the host
104116
* @param size Size of the buffer in bytes
105-
* @return Number of sent bytes on success, negative error
106-
* code on failure
117+
* @retval int Number of sent bytes on success
118+
* @retval NSAPI_ERROR_NO_SOCKET in case socket was not created correctly
119+
* @retval NSAPI_ERROR_WOULD_BLOCK in case non-blocking mode is enabled
120+
* and send cannot be performed immediately
121+
* @retval int Other negative error codes for stack-related failures.
122+
* See \ref NetworkStack::socket_send.
107123
*/
108124
virtual nsapi_size_or_error_t send(const void *data, nsapi_size_t size);
109125

@@ -118,10 +134,12 @@ class TCPSocket : public InternetSocket {
118134
*
119135
* @param data Destination buffer for data received from the host
120136
* @param size Size of the buffer in bytes
121-
* @return Number of received bytes on success, negative error
122-
* code on failure. If no data is available to be received
123-
* and the peer has performed an orderly shutdown,
124-
* recv() returns 0.
137+
* @retval int Number of received bytes on success
138+
* @retval NSAPI_ERROR_NO_SOCKET in case socket was not created correctly
139+
* @retval NSAPI_ERROR_WOULD_BLOCK in case non-blocking mode is enabled
140+
* and send cannot be performed immediately
141+
* @retval int Other negative error codes for stack-related failures.
142+
* See \ref NetworkStack::socket_recv.
125143
*/
126144
virtual nsapi_size_or_error_t recv(void *data, nsapi_size_t size);
127145

@@ -136,8 +154,12 @@ class TCPSocket : public InternetSocket {
136154
* @param address Remote address
137155
* @param data Buffer of data to send to the host
138156
* @param size Size of the buffer in bytes
139-
* @return Number of sent bytes on success, negative error
140-
* code on failure
157+
* @retval int Number of sent bytes on success
158+
* @retval NSAPI_ERROR_NO_SOCKET in case socket was not created correctly
159+
* @retval NSAPI_ERROR_WOULD_BLOCK in case non-blocking mode is enabled
160+
* and send cannot be performed immediately
161+
* @retval int Other negative error codes for stack-related failures.
162+
* See \ref NetworkStack::socket_send.
141163
*/
142164
virtual nsapi_size_or_error_t sendto(const SocketAddress &address,
143165
const void *data, nsapi_size_t size);
@@ -154,8 +176,12 @@ class TCPSocket : public InternetSocket {
154176
* @param address Destination for the source address or NULL
155177
* @param data Destination buffer for datagram received from the host
156178
* @param size Size of the buffer in bytes
157-
* @return Number of received bytes on success, negative error
158-
* code on failure
179+
* @retval int Number of received bytes on success
180+
* @retval NSAPI_ERROR_NO_SOCKET in case socket was not created correctly
181+
* @retval NSAPI_ERROR_WOULD_BLOCK in case non-blocking mode is enabled
182+
* and send cannot be performed immediately
183+
* @retval int Other negative error codes for stack-related failures.
184+
* See \ref NetworkStack::socket_recv.
159185
*/
160186
virtual nsapi_size_or_error_t recvfrom(SocketAddress *address,
161187
void *data, nsapi_size_t size);
@@ -182,7 +208,10 @@ class TCPSocket : public InternetSocket {
182208
*
183209
* @param backlog Number of pending connections that can be queued
184210
* simultaneously, defaults to 1
185-
* @return 0 on success, negative error code on failure
211+
* @retval NSAPI_ERROR_OK on success
212+
* @retval NSAPI_ERROR_NO_SOCKET in case socket was not created correctly
213+
* @retval int Other negative error codes for stack-related failures.
214+
* See \ref NetworkStack::socket_listen.
186215
*/
187216
virtual nsapi_error_t listen(int backlog = 1);
188217

0 commit comments

Comments
 (0)