stream_peer_tcp_posix.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*************************************************************************/
  2. /* stream_peer_tcp_posix.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifdef UNIX_ENABLED
  31. #ifndef STREAM_PEER_TCP_POSIX_H
  32. #define STREAM_PEER_TCP_POSIX_H
  33. #include "core/io/ip_address.h"
  34. #include "core/io/stream_peer_tcp.h"
  35. #include "error_list.h"
  36. class StreamPeerTCPPosix : public StreamPeerTCP {
  37. protected:
  38. mutable Status status;
  39. IP::Type sock_type;
  40. int sockfd;
  41. Error _block(int p_sockfd, bool p_read, bool p_write) const;
  42. Error _poll_connection() const;
  43. IP_Address peer_host;
  44. int peer_port;
  45. Error write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block);
  46. Error read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block);
  47. static StreamPeerTCP *_create();
  48. public:
  49. virtual Error connect_to_host(const IP_Address &p_host, uint16_t p_port);
  50. virtual Error put_data(const uint8_t *p_data, int p_bytes);
  51. virtual Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent);
  52. virtual Error get_data(uint8_t *p_buffer, int p_bytes);
  53. virtual Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received);
  54. virtual int get_available_bytes() const;
  55. void set_socket(int p_sockfd, IP_Address p_host, int p_port, IP::Type p_sock_type);
  56. virtual IP_Address get_connected_host() const;
  57. virtual uint16_t get_connected_port() const;
  58. virtual bool is_connected_to_host() const;
  59. virtual Status get_status() const;
  60. virtual void disconnect_from_host();
  61. virtual void set_nodelay(bool p_enabled);
  62. static void make_default();
  63. StreamPeerTCPPosix();
  64. ~StreamPeerTCPPosix();
  65. };
  66. #endif // TCP_CLIENT_POSIX_H
  67. #endif