1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-16 14:00:40 +00:00

Websocket peer outbound buffer fixes. Expose outbound buffered amount.

(cherry picked from commit 023548c0a5)
This commit is contained in:
Jordan Schidlowsky
2021-07-29 14:11:27 -06:00
committed by Rémi Verschelde
parent 6a0155393a
commit 6878fe6d88
10 changed files with 60 additions and 5 deletions

View File

@@ -33,11 +33,11 @@
#include "emws_peer.h"
#include "core/io/ip.h"
void EMWSPeer::set_sock(int p_sock, unsigned int p_in_buf_size, unsigned int p_in_pkt_size) {
void EMWSPeer::set_sock(int p_sock, unsigned int p_in_buf_size, unsigned int p_in_pkt_size, unsigned int p_out_buf_size) {
peer_sock = p_sock;
_in_buffer.resize(p_in_pkt_size, p_in_buf_size);
_packet_buffer.resize((1 << p_in_buf_size));
_out_buf_size = p_out_buf_size;
}
void EMWSPeer::set_write_mode(WriteMode p_mode) {
@@ -55,8 +55,10 @@ Error EMWSPeer::read_msg(const uint8_t *p_data, uint32_t p_size, bool p_is_strin
}
Error EMWSPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
ERR_FAIL_COND_V(_out_buf_size && (godot_js_websocket_buffered_amount(peer_sock) >= (1ULL << _out_buf_size)), ERR_OUT_OF_MEMORY);
int is_bin = write_mode == WebSocketPeer::WRITE_MODE_BINARY ? 1 : 0;
godot_js_websocket_send(peer_sock, p_buffer, p_buffer_size, is_bin);
return OK;
};
@@ -82,6 +84,13 @@ int EMWSPeer::get_available_packet_count() const {
return _in_buffer.packets_left();
};
int EMWSPeer::get_current_outbound_buffered_amount() const {
if (peer_sock != -1) {
return godot_js_websocket_buffered_amount(peer_sock);
}
return 0;
}
bool EMWSPeer::was_string_packet() const {
return _is_string;
@@ -118,6 +127,7 @@ void EMWSPeer::set_no_delay(bool p_enabled) {
}
EMWSPeer::EMWSPeer() {
_out_buf_size = 0;
peer_sock = -1;
write_mode = WRITE_MODE_BINARY;
close();