Websockets: Fix buffer size checks in put_packet()
This commit is contained in:
parent
ecedc7df0b
commit
6a92a2e92d
2 changed files with 8 additions and 6 deletions
|
@ -54,11 +54,14 @@ 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 && ((uint64_t)godot_js_websocket_buffered_amount(peer_sock) >= (1ULL << _out_buf_size)), ERR_OUT_OF_MEMORY);
|
||||
ERR_FAIL_COND_V(_out_buf_size && ((uint64_t)godot_js_websocket_buffered_amount(peer_sock) + p_buffer_size >= (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);
|
||||
if (godot_js_websocket_send(peer_sock, p_buffer, p_buffer_size, is_bin) != 0) {
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
return OK;
|
||||
};
|
||||
|
||||
|
|
|
@ -242,15 +242,14 @@ void WSLPeer::poll() {
|
|||
Error WSLPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
|
||||
ERR_FAIL_COND_V(!is_connected_to_host(), FAILED);
|
||||
ERR_FAIL_COND_V(_out_pkt_size && (wslay_event_get_queued_msg_count(_data->ctx) >= (1ULL << _out_pkt_size)), ERR_OUT_OF_MEMORY);
|
||||
ERR_FAIL_COND_V(_out_buf_size && (wslay_event_get_queued_msg_length(_data->ctx) >= (1ULL << _out_buf_size)), ERR_OUT_OF_MEMORY);
|
||||
ERR_FAIL_COND_V(_out_buf_size && (wslay_event_get_queued_msg_length(_data->ctx) + p_buffer_size >= (1ULL << _out_buf_size)), ERR_OUT_OF_MEMORY);
|
||||
|
||||
struct wslay_event_msg msg; // Should I use fragmented?
|
||||
struct wslay_event_msg msg;
|
||||
msg.opcode = write_mode == WRITE_MODE_TEXT ? WSLAY_TEXT_FRAME : WSLAY_BINARY_FRAME;
|
||||
msg.msg = p_buffer;
|
||||
msg.msg_length = p_buffer_size;
|
||||
|
||||
wslay_event_queue_msg(_data->ctx, &msg);
|
||||
if (wslay_event_send(_data->ctx) < 0) {
|
||||
if (wslay_event_queue_msg(_data->ctx, &msg) != 0 || wslay_event_send(_data->ctx) != 0) {
|
||||
close_now();
|
||||
return FAILED;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue