Skip to content

Commit

Permalink
relay: fix using the wrong size for the send loop
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoru committed Jan 20, 2025
1 parent 223643a commit acbb229
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/server/relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void send_sbuffer(SOCKET s, msgpack_sbuffer* sbuf) {
memcpy(data + sizeof(MAGIC), &sbuf->size, sizeof (uint32_t));
memcpy(data + HEADER_SIZE, sbuf->data, sbuf->size);

while (sent < sbuf->size) {
while (sent < size) {
int n = send(s, data + sent, size - sent, 0);
if (n == -1) {
#ifdef WIN32
Expand Down Expand Up @@ -248,10 +248,10 @@ qboolean vrx_relay_try_message_relay(msgpack_object_str *type, msgpack_object_ar
}

typedef enum {
RESULT_INVALID,
RESULT_NEED_MORE_DATA,
RESULT_CONTINUE,
RESULT_SUCCESS
RESULT_INVALID, // "we got an invalid message"
RESULT_NEED_MORE_DATA, // "we need more data to parse the message"
RESULT_CONTINUE, // "we got a message successfully, but continue parsing"
RESULT_SUCCESS // "we got a message successfully, but stop parsing."
} relay_parse_result_t;

relay_parse_result_t vrx_relay_parse_message(size_t* start) {
Expand Down Expand Up @@ -396,9 +396,11 @@ void vrx_relay_recv() {
case RESULT_NEED_MORE_DATA:
case RESULT_SUCCESS:
continue_parsing = false;

// az: we need to wait for more data, memmove the reminder to the beginning
memmove(pending_buf, pending_buf + start, pending_buf_size - start);
pending_buf_size -= start;
start = 0;
break;
case RESULT_CONTINUE:
break;
Expand Down

0 comments on commit acbb229

Please sign in to comment.