summaryrefslogtreecommitdiff
path: root/core/io/stream_peer_tcp.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/stream_peer_tcp.h')
-rw-r--r--core/io/stream_peer_tcp.h38
1 files changed, 26 insertions, 12 deletions
diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h
index dcda3b5bd7..de364915cd 100644
--- a/core/io/stream_peer_tcp.h
+++ b/core/io/stream_peer_tcp.h
@@ -33,6 +33,7 @@
#include "core/io/ip.h"
#include "core/io/ip_address.h"
+#include "core/io/net_socket.h"
#include "core/io/stream_peer.h"
class StreamPeerTCP : public StreamPeer {
@@ -50,24 +51,37 @@ public:
};
protected:
- virtual Error _connect(const String &p_address, int p_port);
- static StreamPeerTCP *(*_create)();
+ Ref<NetSocket> _sock;
+ Status status;
+ IP_Address peer_host;
+ uint16_t peer_port;
+
+ Error _connect(const String &p_address, int p_port);
+ Error _poll_connection();
+ Error write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block);
+ Error read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block);
+
static void _bind_methods();
public:
- virtual Error connect_to_host(const IP_Address &p_host, uint16_t p_port) = 0;
+ void accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port);
+
+ Error connect_to_host(const IP_Address &p_host, uint16_t p_port);
+ bool is_connected_to_host() const;
+ IP_Address get_connected_host() const;
+ uint16_t get_connected_port() const;
+ void disconnect_from_host();
- //read/write from streampeer
+ int get_available_bytes() const;
+ Status get_status();
- virtual bool is_connected_to_host() const = 0;
- virtual Status get_status() const = 0;
- virtual void disconnect_from_host() = 0;
- virtual IP_Address get_connected_host() const = 0;
- virtual uint16_t get_connected_port() const = 0;
- virtual void set_no_delay(bool p_enabled) = 0;
+ void set_no_delay(bool p_enabled);
- static Ref<StreamPeerTCP> create_ref();
- static StreamPeerTCP *create();
+ // Read/Write from StreamPeer
+ Error put_data(const uint8_t *p_data, int p_bytes);
+ Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent);
+ Error get_data(uint8_t *p_buffer, int p_bytes);
+ Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received);
StreamPeerTCP();
~StreamPeerTCP();