Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UDPSocket.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef UDPSOCKET_H
  19. #define UDPSOCKET_H
  20. #include "Socket/Socket.h"
  21. #include "Socket/Endpoint.h"
  22. /**
  23. UDP Socket
  24. */
  25. class UDPSocket : public Socket {
  26. public:
  27. /** Instantiate an UDP Socket.
  28. */
  29. UDPSocket();
  30. /** Init the UDP Client Socket without binding it to any specific port
  31. \return 0 on success, -1 on failure.
  32. */
  33. int init(void);
  34. /** Bind a UDP Server Socket to a specific port
  35. \param port The port to listen for incoming connections on
  36. \return 0 on success, -1 on failure.
  37. */
  38. int bind(int port);
  39. /** Join the multicast group at the given address
  40. \param address The address of the multicast group
  41. \return 0 on success, -1 on failure.
  42. */
  43. int join_multicast_group(const char* address);
  44. /** Set the socket in broadcasting mode
  45. \return 0 on success, -1 on failure.
  46. */
  47. int set_broadcasting(bool broadcast=true);
  48. /** Send a packet to a remote endpoint
  49. \param remote The remote endpoint
  50. \param packet The packet to be sent
  51. \param length The length of the packet to be sent
  52. \return the number of written bytes on success (>=0) or -1 on failure
  53. */
  54. int sendTo(Endpoint &remote, char *packet, int length);
  55. /** Receive a packet from a remote endpoint
  56. \param remote The remote endpoint
  57. \param buffer The buffer for storing the incoming packet data. If a packet
  58. is too long to fit in the supplied buffer, excess bytes are discarded
  59. \param length The length of the buffer
  60. \return the number of received bytes on success (>=0) or -1 on failure
  61. */
  62. int receiveFrom(Endpoint &remote, char *buffer, int length);
  63. };
  64. #endif