diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-08-08 20:55:22 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-08-08 20:55:22 -0300 |
commit | 90a595ac4273dbf79809c810421f1f439c78e452 (patch) | |
tree | 365ce15ad643fc36fc44f81f99481f9d6b5b6dec /core | |
parent | df573f5c3a76155842e43ea0dbab594e3944b114 (diff) |
Set some reasonable limits for sending information to the debugger, closes #5848
Diffstat (limited to 'core')
-rw-r--r-- | core/io/packet_peer.cpp | 30 | ||||
-rw-r--r-- | core/io/packet_peer.h | 4 | ||||
-rw-r--r-- | core/script_debugger_remote.cpp | 1 |
3 files changed, 23 insertions, 12 deletions
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index a3d33593dd..40082cc481 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -139,6 +139,8 @@ void PacketPeerStream::_set_stream_peer(REF p_peer) { void PacketPeerStream::_bind_methods() { ClassDB::bind_method(D_METHOD("set_stream_peer", "peer:StreamPeer"), &PacketPeerStream::_set_stream_peer); + ClassDB::bind_method(D_METHOD("set_input_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_input_buffer_max_size); + ClassDB::bind_method(D_METHOD("set_output_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_output_buffer_max_size); } Error PacketPeerStream::_poll_buffer() const { @@ -146,13 +148,13 @@ Error PacketPeerStream::_poll_buffer() const { ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED); int read = 0; - Error err = peer->get_partial_data(&temp_buffer[0], ring_buffer.space_left(), read); + Error err = peer->get_partial_data(&input_buffer[0], ring_buffer.space_left(), read); if (err) return err; if (read == 0) return OK; - int w = ring_buffer.write(&temp_buffer[0], read); + int w = ring_buffer.write(&input_buffer[0], read); ERR_FAIL_COND_V(w != read, ERR_BUG); return OK; @@ -198,9 +200,9 @@ Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size) ERR_FAIL_COND_V(remaining < (int)len, ERR_UNAVAILABLE); ring_buffer.read(lbuf, 4); //get rid of first 4 bytes - ring_buffer.read(&temp_buffer[0], len); // read packet + ring_buffer.read(&input_buffer[0], len); // read packet - *r_buffer = &temp_buffer[0]; + *r_buffer = &input_buffer[0]; r_buffer_size = len; return OK; } @@ -217,19 +219,19 @@ Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) { return OK; ERR_FAIL_COND_V(p_buffer_size < 0, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(p_buffer_size + 4 > temp_buffer.size(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(p_buffer_size + 4 > output_buffer.size(), ERR_INVALID_PARAMETER); - encode_uint32(p_buffer_size, &temp_buffer[0]); - uint8_t *dst = &temp_buffer[4]; + encode_uint32(p_buffer_size, &output_buffer[0]); + uint8_t *dst = &output_buffer[4]; for (int i = 0; i < p_buffer_size; i++) dst[i] = p_buffer[i]; - return peer->put_data(&temp_buffer[0], p_buffer_size + 4); + return peer->put_data(&output_buffer[0], p_buffer_size + 4); } int PacketPeerStream::get_max_packet_size() const { - return temp_buffer.size(); + return output_buffer.size(); } void PacketPeerStream::set_stream_peer(const Ref<StreamPeer> &p_peer) { @@ -249,7 +251,12 @@ void PacketPeerStream::set_input_buffer_max_size(int p_max_size) { ERR_EXPLAIN("Buffer in use, resizing would cause loss of data"); ERR_FAIL_COND(ring_buffer.data_left()); ring_buffer.resize(nearest_shift(p_max_size + 4)); - temp_buffer.resize(nearest_power_of_2(p_max_size + 4)); + input_buffer.resize(nearest_power_of_2(p_max_size + 4)); +} + +void PacketPeerStream::set_output_buffer_max_size(int p_max_size) { + + output_buffer.resize(nearest_power_of_2(p_max_size + 4)); } PacketPeerStream::PacketPeerStream() { @@ -257,5 +264,6 @@ PacketPeerStream::PacketPeerStream() { int rbsize = GLOBAL_GET("network/limits/packet_peer_stream/max_buffer_po2"); ring_buffer.resize(rbsize); - temp_buffer.resize(1 << rbsize); + input_buffer.resize(1 << rbsize); + output_buffer.resize(1 << rbsize); } diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h index 95806aa511..ed6b252d80 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -75,7 +75,8 @@ class PacketPeerStream : public PacketPeer { mutable Ref<StreamPeer> peer; mutable RingBuffer<uint8_t> ring_buffer; - mutable Vector<uint8_t> temp_buffer; + mutable Vector<uint8_t> input_buffer; + mutable Vector<uint8_t> output_buffer; Error _poll_buffer() const; @@ -92,6 +93,7 @@ public: void set_stream_peer(const Ref<StreamPeer> &p_peer); void set_input_buffer_max_size(int p_max_size); + void set_output_buffer_max_size(int p_max_size); PacketPeerStream(); }; diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index fdde08bb32..6f12338f66 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -945,6 +945,7 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() { tcp_client = StreamPeerTCP::create_ref(); packet_peer_stream = Ref<PacketPeerStream>(memnew(PacketPeerStream)); packet_peer_stream->set_stream_peer(tcp_client); + packet_peer_stream->set_output_buffer_max_size(1024 * 1024 * 8); //8mb should be way more than enough mutex = Mutex::create(); locking = false; |