26
26
#include " rtos/EventFlags.h"
27
27
28
28
29
- /* * UDP socket
29
+ /* * UDP socket implementation.
30
30
*/
31
31
class UDPSocket : public InternetSocket {
32
32
public:
33
- /* * Create an uninitialized socket
33
+ /* * Create an uninitialized socket.
34
34
*
35
- * Must call open to initialize the socket on a network stack.
35
+ * @note Must call open to initialize the socket on a network stack.
36
36
*/
37
37
UDPSocket ();
38
38
39
- /* * Create a socket on a network interface
40
- *
41
- * Creates and opens a socket on the network stack of the given
39
+ /* * Create and open a socket on the network stack of the given
42
40
* network interface.
43
41
*
44
- * @param stack Network stack as target for socket
42
+ * @tparam S Type of the Network stack.
43
+ * @param stack Network stack as target for socket.
45
44
*/
46
45
template <typename S>
47
46
UDPSocket (S *stack)
48
47
{
49
48
open (stack);
50
49
}
51
50
52
- /* * Destroy a socket
51
+ /* * Destroy a socket.
53
52
*
54
- * Closes socket if the socket is still open
53
+ * @note Closes socket if the socket is still open.
55
54
*/
56
55
virtual ~UDPSocket ();
57
56
58
- /* * Send a packet over a UDP socket
59
- *
60
- * Sends data to the specified address specified by either a domain name
61
- * or an IP address and port. Returns the number of bytes sent from the
62
- * buffer.
57
+ /* * Send data to the specified host and port.
63
58
*
64
59
* By default, sendto blocks until data is sent. If socket is set to
65
60
* non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned
66
61
* immediately.
67
62
*
68
- * @param host Hostname of the remote host
69
- * @param port Port of the remote host
70
- * @param data Buffer of data to send to the host
71
- * @param size Size of the buffer in bytes
63
+ * @param host Domain name of the remote host or a dotted notation IP address.
64
+ * @param port Port of the remote host.
65
+ * @param data Buffer of data to send to the host.
66
+ * @param size Size of the buffer in bytes.
72
67
* @return Number of sent bytes on success, negative error
73
- * code on failure
68
+ * code on failure.
74
69
*/
75
70
virtual nsapi_size_or_error_t sendto (const char *host, uint16_t port,
76
71
const void *data, nsapi_size_t size);
77
72
78
- /* * Send a packet over a UDP socket
79
- *
80
- * Sends data to the specified address. Returns the number of bytes
81
- * sent from the buffer.
73
+ /* * Send data to the specified address.
82
74
*
83
75
* By default, sendto blocks until data is sent. If socket is set to
84
76
* non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned
85
77
* immediately.
86
78
*
87
- * @param address The SocketAddress of the remote host
88
- * @param data Buffer of data to send to the host
89
- * @param size Size of the buffer in bytes
79
+ * @param address The SocketAddress of the remote host.
80
+ * @param data Buffer of data to send to the host.
81
+ * @param size Size of the buffer in bytes.
90
82
* @return Number of sent bytes on success, negative error
91
- * code on failure
83
+ * code on failure.
92
84
*/
93
85
virtual nsapi_size_or_error_t sendto (const SocketAddress &address,
94
86
const void *data, nsapi_size_t size);
95
87
96
- /* * Receive a datagram over a UDP socket
88
+ /* * Receive a datagram and store the source address in address if it's not NULL.
89
+ *
90
+ * By default, recvfrom blocks until a datagram is received. If socket is set to
91
+ * non-blocking or times out with no datagram, NSAPI_ERROR_WOULD_BLOCK
92
+ * is returned.
97
93
*
98
- * Receives a datagram and stores the source address in address if address
99
- * is not NULL. Returns the number of bytes written into the buffer. If the
100
- * datagram is larger than the buffer, the excess data is silently discarded.
94
+ * @note If the datagram is larger than the buffer, the excess data is silently discarded.
101
95
*
102
- * If socket is connected, only packets coming from connected peer address
96
+ * @note If socket is connected, only packets coming from connected peer address
103
97
* are accepted.
104
98
*
105
99
* @note recvfrom() is allowed write to address and data buffers even if error occurs.
106
100
*
107
- * By default, recvfrom blocks until a datagram is received. If socket is set to
108
- * non-blocking or times out with no datagram, NSAPI_ERROR_WOULD_BLOCK
109
- * is returned.
110
- *
111
- * @param address Destination for the source address or NULL
112
- * @param data Destination buffer for datagram received from the host
113
- * @param size Size of the buffer in bytes
101
+ * @param address Destination for the source address or NULL.
102
+ * @param data Destination buffer for datagram received from the host.
103
+ * @param size Size of the buffer in bytes.
114
104
* @return Number of received bytes on success, negative error
115
- * code on failure
105
+ * code on failure.
116
106
*/
117
107
virtual nsapi_size_or_error_t recvfrom (SocketAddress *address,
118
108
void *data, nsapi_size_t size);
119
109
120
- /* * Set remote peer address
121
- *
122
- * Set the remote address for next send() call and filtering
123
- * for incomming packets. To reset the address, zero initialised
110
+ /* * Set the remote address for next send() call and filtering
111
+ * of incoming packets. To reset the address, zero initialised
124
112
* SocketAddress must be in the address parameter.
125
113
*
126
- * @param address The SocketAddress of the remote host
127
- * @return 0 on success, negative error code on failure
114
+ * @param address The SocketAddress of the remote host.
115
+ * @return 0 on success, negative error code on failure.
128
116
*/
129
117
virtual nsapi_error_t connect (const SocketAddress &address);
130
118
131
- /* * Send a datagram to pre-specified remote.
132
- *
133
- * The socket must be connected to a remote host before send() call.
134
- * Returns the number of bytes sent from the buffer.
119
+ /* * Send a datagram to connected remote address.
135
120
*
136
121
* By default, send blocks until all data is sent. If socket is set to
137
122
* non-blocking or times out, a partial amount can be written.
138
123
* NSAPI_ERROR_WOULD_BLOCK is returned if no data was written.
139
124
*
140
- * @param data Buffer of data to send to the host
141
- * @param size Size of the buffer in bytes
125
+ * @note The socket must be connected to a remote host before send() call.
126
+ *
127
+ * @param data Buffer of data to send to the host.
128
+ * @param size Size of the buffer in bytes.
142
129
* @return Number of sent bytes on success, negative error
143
130
* code on failure.
144
131
*/
@@ -151,35 +138,39 @@ class UDPSocket : public InternetSocket {
151
138
* If socket is connected, only packets coming from connected peer address
152
139
* are accepted.
153
140
*
154
- * @note recv() is allowed write to data buffer even if error occurs.
155
- *
156
141
* By default, recv blocks until some data is received. If socket is set to
157
142
* non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK can be returned to
158
143
* indicate no data.
159
144
*
160
- * @param data Destination buffer for data received from the host
161
- * @param size Size of the buffer in bytes
145
+ * @note recv() is allowed write to data buffer even if error occurs.
146
+ *
147
+ * @param data Pointer to buffer for data received from the host.
148
+ * @param size Size of the buffer in bytes.
162
149
* @return Number of received bytes on success, negative error
163
150
* code on failure.
164
151
*/
165
152
virtual nsapi_size_or_error_t recv (void *data, nsapi_size_t size);
166
153
167
- /* * Not implemented for UDP
154
+ /* * Not implemented for UDP.
168
155
*
169
- * @param error unused
156
+ * @param error Not used.
170
157
* @return NSAPI_ERROR_UNSUPPORTED
171
158
*/
172
159
virtual Socket *accept (nsapi_error_t *error = NULL );
173
160
174
- /* * Not implemented for UDP
161
+ /* * Not implemented for UDP.
175
162
*
176
- * @param backlog unused
163
+ * @param backlog Not used.
177
164
* @return NSAPI_ERROR_UNSUPPORTED
178
165
*/
179
166
virtual nsapi_error_t listen (int backlog = 1 );
180
167
168
+ #if !defined(DOXYGEN_ONLY)
169
+
181
170
protected:
182
171
virtual nsapi_protocol_t get_proto ();
172
+
173
+ #endif // !defined(DOXYGEN_ONLY)
183
174
};
184
175
185
176
0 commit comments