28
28
/* * Socket interface.
29
29
*
30
30
* This class defines the Mbed OS Socket API.
31
- * Socket is an abstract interface for communicating to remote endpoints.
31
+ * Socket is an abstract interface for communicating with remote endpoints.
32
32
*
33
- * This API is intented to use for applications and libraries instead of
34
- * using some protocol specific implementation of it . For example TCPSocket
35
- * and UDPSocket are implementations of Socket interface.
36
- * Socket API is intentionally not protocol specific and allows all protocol
37
- * to provide same API regardless of underlying transport mechanism.
33
+ * This API is intented for applications and libraries instead of
34
+ * protocol- specific implementations . For example, TCPSocket
35
+ * and UDPSocket are implementations of the Socket interface.
36
+ * Socket API is intentionally not protocol- specific, and allows all protocol
37
+ * to provide the same API regardless of the underlying transport mechanism.
38
38
*/
39
39
class Socket {
40
40
public:
41
41
/* * Destroy a socket.
42
42
*
43
- * Closes socket if the socket is still open
43
+ * Closes socket if the socket is still open.
44
44
*/
45
45
virtual ~Socket () {}
46
46
47
- /* * Close the socket.
47
+ /* * Closes the socket.
48
48
*
49
49
* Closes any open connection and deallocates any memory associated
50
50
* with the socket. Called from destructor if socket is not closed.
@@ -55,53 +55,53 @@ class Socket {
55
55
56
56
/* * Connects socket to a remote address.
57
57
*
58
- * Attempt to make connection on connection-mode protocol or set or reset
58
+ * Attempts to make connection on connection-mode protocol or set or reset
59
59
* the peer address on connectionless protocol.
60
60
*
61
- * Also connectionless protocols use the connected address to filter
61
+ * Connectionless protocols also use the connected address to filter
62
62
* incoming packets for recv() and recvfrom() calls.
63
63
*
64
- * To reset the peer address, zero initialized(default constructor) SocketAddress
65
- * object have to be in the address parameter.
64
+ * To reset the peer address, there must be zero initialized(default constructor) SocketAddress
65
+ * objects in the address parameter.
66
66
*
67
- * @param address The SocketAddress of the remote peer
68
- * @return NSAPI_ERROR_OK on success, negative error code on failure
67
+ * @param address The SocketAddress of the remote peer.
68
+ * @return NSAPI_ERROR_OK on success, negative error code on failure.
69
69
*/
70
70
virtual nsapi_error_t connect (const SocketAddress &address) = 0;
71
71
72
72
/* * Send data on a socket
73
73
*
74
74
* The socket must be connected to a remote host before send() call.
75
75
* Returns the number of bytes sent from the buffer.
76
- * In case of connectionless socket, send data to pre-specified remote.
76
+ * In case of connectionless socket, sends data to pre-specified remote.
77
77
*
78
78
* By default, send blocks until all data is sent. If socket is set to
79
79
* non-blocking or times out, a partial amount can be written.
80
80
* NSAPI_ERROR_WOULD_BLOCK is returned if no data was written.
81
81
*
82
- * @param data Buffer of data to send to the host
83
- * @param size Size of the buffer in bytes
82
+ * @param data Buffer of data to send to the host.
83
+ * @param size Size of the buffer in bytes.
84
84
* @return Number of sent bytes on success, negative error
85
85
* code on failure.
86
86
*/
87
87
virtual nsapi_size_or_error_t send (const void *data, nsapi_size_t size) = 0;
88
88
89
89
/* * Receive data from a socket.
90
90
*
91
- * Receive data from connected socket or in case of connectionless socket
92
- * this is equivalent of calling recvfrom(NULL, data, size).
91
+ * Receive data from connected socket, or in the case of connectionless socket,
92
+ * equivalent to calling recvfrom(NULL, data, size).
93
93
*
94
94
* If socket is connected, only packets coming from connected peer address
95
95
* are accepted.
96
96
*
97
- * @note recv() is allowed write to data buffer even if error occurs.
97
+ * @note recv() is allowed write to data buffer even if an error occurs.
98
98
*
99
99
* By default, recv blocks until some data is received. If socket is set to
100
100
* non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK can be returned to
101
101
* indicate no data.
102
102
*
103
- * @param data Destination buffer for data received from the host
104
- * @param size Size of the buffer in bytes
103
+ * @param data Destination buffer for data received from the host.
104
+ * @param size Size of the buffer in bytes.
105
105
* @return Number of received bytes on success, negative error
106
106
* code on failure. If no data is available to be received
107
107
* and the peer has performed an orderly shutdown,
@@ -111,9 +111,9 @@ class Socket {
111
111
112
112
/* * Send a message on a socket.
113
113
*
114
- * The sendto() function shall send a message through a connection-mode or connectionless-mode socket.
115
- * If the socket is connectionless-mode, the message shall be sent to the address specified.
116
- * If the socket is connection-mode, address shall be ignored.
114
+ * The sendto() function sends a message through a connection-mode or connectionless-mode socket.
115
+ * If the socket is in connectionless-mode, the message is sent to the address specified.
116
+ * If the socket is in connection-mode, address is ignored.
117
117
*
118
118
* By default, sendto blocks until data is sent. If socket is set to
119
119
* non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned
@@ -156,7 +156,7 @@ class Socket {
156
156
* Binding a socket specifies the address and port on which to receive
157
157
* data. If the IP address is zeroed, only the port is bound.
158
158
*
159
- * @param address Local address to bind
159
+ * @param address Local address to bind.
160
160
* @return NSAPI_ERROR_OK on success, negative error code on failure.
161
161
*/
162
162
virtual nsapi_error_t bind (const SocketAddress &address) = 0;
@@ -165,7 +165,7 @@ class Socket {
165
165
*
166
166
* Initially all sockets are in blocking mode. In non-blocking mode
167
167
* blocking operations such as send/recv/accept return
168
- * NSAPI_ERROR_WOULD_BLOCK if they can not continue.
168
+ * NSAPI_ERROR_WOULD_BLOCK if they cannot continue.
169
169
*
170
170
* set_blocking(false) is equivalent to set_timeout(0)
171
171
* set_blocking(true) is equivalent to set_timeout(-1)
@@ -179,7 +179,7 @@ class Socket {
179
179
* Initially all sockets have unbounded timeouts. NSAPI_ERROR_WOULD_BLOCK
180
180
* is returned if a blocking operation takes longer than the specified
181
181
* timeout. A timeout of 0 removes the timeout from the socket. A negative
182
- * value give the socket an unbounded timeout.
182
+ * value gives the socket an unbounded timeout.
183
183
*
184
184
* set_timeout(0) is equivalent to set_blocking(false)
185
185
* set_timeout(-1) is equivalent to set_blocking(true)
@@ -190,17 +190,17 @@ class Socket {
190
190
191
191
/* * Register a callback on state change of the socket.
192
192
*
193
- * The specified callback will be called on state changes such as when
194
- * the socket can recv /send/accept successfully and on when an error
193
+ * The specified callback is called on state changes, such as when
194
+ * the socket can receive /send/accept successfully and when an error
195
195
* occurs. The callback may also be called spuriously without reason.
196
196
*
197
197
* The callback may be called in an interrupt context and should not
198
- * perform expensive operations such as recv /send calls.
198
+ * perform expensive operations such as receive /send calls.
199
199
*
200
200
* Note! This is not intended as a replacement for a poll or attach-like
201
- * asynchronous api , but rather as a building block for constructing
202
- * such functionality. The exact timing of when the registered function
203
- * is called is not guaranteed and susceptible to change.
201
+ * asynchronous API , but rather as a building block for constructing
202
+ * such functionality. The exact timing of the registered function
203
+ * is not guaranteed and susceptible to change.
204
204
*
205
205
* @param func Function to call on state change.
206
206
*/
@@ -243,15 +243,15 @@ class Socket {
243
243
/* * Accepts a connection on a socket.
244
244
*
245
245
* The server socket must be bound and set to listen for connections.
246
- * On a new connection, returns connected network socket which user is expected to call close()
247
- * and that deallocates the resources. Referencing a returned pointer after a close()
246
+ * On a new connection, returns connected network socket to call close()
247
+ * that deallocates the resources. Referencing a returned pointer after a close()
248
248
* call is not allowed and leads to undefined behavior.
249
249
*
250
250
* By default, accept blocks until incoming connection occurs. If socket is set to
251
251
* non-blocking or times out, error is set to NSAPI_ERROR_WOULD_BLOCK.
252
252
*
253
- * @param error pointer to storage of the error value or NULL
254
- * @return pointer to a socket
253
+ * @param error Pointer to storage of the error value or NULL.
254
+ * @return Pointer to a socket.
255
255
*/
256
256
virtual Socket *accept (nsapi_error_t *error = NULL ) = 0;
257
257
@@ -261,8 +261,8 @@ class Socket {
261
261
* incoming connections.
262
262
*
263
263
* @param backlog Number of pending connections that can be queued
264
- * simultaneously, defaults to 1
265
- * @return NSAPI_ERROR_OK on success, negative error code on failure
264
+ * simultaneously, defaults to 1.
265
+ * @return NSAPI_ERROR_OK on success, negative error code on failure.
266
266
*/
267
267
virtual nsapi_error_t listen (int backlog = 1 ) = 0;
268
268
0 commit comments