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.

TCPSocketConnection.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 TCPSOCKET_H
  19. #define TCPSOCKET_H
  20. #include "Socket/Socket.h"
  21. #include "Socket/Endpoint.h"
  22. /**
  23. TCP socket connection
  24. */
  25. class TCPSocketConnection : public Socket, public Endpoint {
  26. friend class TCPSocketServer;
  27. public:
  28. /** TCP socket connection
  29. */
  30. TCPSocketConnection();
  31. /** Connects this TCP socket to the server
  32. \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
  33. \param port The host's port to connect to.
  34. \return 0 on success, -1 on failure.
  35. */
  36. int connect(const char* host, const int port);
  37. /** Check if the socket is connected
  38. \return true if connected, false otherwise.
  39. */
  40. bool is_connected(void);
  41. /** Send data to the remote host.
  42. \param data The buffer to send to the host.
  43. \param length The length of the buffer to send.
  44. \return the number of written bytes on success (>=0) or -1 on failure
  45. */
  46. int send(char* data, int length);
  47. /** Send all the data to the remote host.
  48. \param data The buffer to send to the host.
  49. \param length The length of the buffer to send.
  50. \return the number of written bytes on success (>=0) or -1 on failure
  51. */
  52. int send_all(char* data, int length);
  53. /** Receive data from the remote host.
  54. \param data The buffer in which to store the data received from the host.
  55. \param length The maximum length of the buffer.
  56. \return the number of received bytes on success (>=0) or -1 on failure
  57. */
  58. int receive(char* data, int length);
  59. /** Receive all the data from the remote host.
  60. \param data The buffer in which to store the data received from the host.
  61. \param length The maximum length of the buffer.
  62. \return the number of received bytes on success (>=0) or -1 on failure
  63. */
  64. int receive_all(char* data, int length);
  65. private:
  66. bool _is_connected;
  67. };
  68. #endif