]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/net/lwip/Socket/UDPSocket.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / net / lwip / Socket / UDPSocket.h
1 /* Copyright (C) 2012 mbed.org, MIT License
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
7 * furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice shall be included in all copies or
10 * substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 */
18
19 #ifndef UDPSOCKET_H
20 #define UDPSOCKET_H
21
22 #include "Socket/Socket.h"
23 #include "Socket/Endpoint.h"
24
25 /**
26 UDP Socket
27 */
28 class UDPSocket : public Socket {
29
30 public:
31 /** Instantiate an UDP Socket.
32 */
33 UDPSocket();
34
35 /** Init the UDP Client Socket without binding it to any specific port
36 \return 0 on success, -1 on failure.
37 */
38 int init(void);
39
40 /** Bind a UDP Server Socket to a specific port
41 \param port The port to listen for incoming connections on
42 \return 0 on success, -1 on failure.
43 */
44 int bind(int port);
45
46 /** Join the multicast group at the given address
47 \param address The address of the multicast group
48 \return 0 on success, -1 on failure.
49 */
50 int join_multicast_group(const char* address);
51
52 /** Set the socket in broadcasting mode
53 \return 0 on success, -1 on failure.
54 */
55 int set_broadcasting(bool broadcast=true);
56
57 /** Send a packet to a remote endpoint
58 \param remote The remote endpoint
59 \param packet The packet to be sent
60 \param length The length of the packet to be sent
61 \return the number of written bytes on success (>=0) or -1 on failure
62 */
63 int sendTo(Endpoint &remote, char *packet, int length);
64
65 /** Receive a packet from a remote endpoint
66 \param remote The remote endpoint
67 \param buffer The buffer for storing the incoming packet data. If a packet
68 is too long to fit in the supplied buffer, excess bytes are discarded
69 \param length The length of the buffer
70 \return the number of received bytes on success (>=0) or -1 on failure
71 */
72 int receiveFrom(Endpoint &remote, char *buffer, int length);
73 };
74
75 #endif
Imprint / Impressum