Skip to content

Commit

Permalink
(Netplay) Copy data on receive, even if the buffer is full (#14344)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cthulhu-throwaway authored Aug 24, 2022
1 parent 9aef0ef commit b59624a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions network/netplay/netplay_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -2371,7 +2371,7 @@ ssize_t netplay_recv(struct socket_buffer *sbuf, int sockfd,
bool error = false;

if (buf_used(sbuf) >= (sbuf->bufsz - 1))
return 0;
goto copy;

/* Receive whatever we can into the buffer */
if (sbuf->end >= sbuf->start)
Expand Down Expand Up @@ -2415,6 +2415,7 @@ ssize_t netplay_recv(struct socket_buffer *sbuf, int sockfd,
}

/* Now copy it into the reader */
copy:
if (sbuf->end >= sbuf->read || (sbuf->bufsz - sbuf->read) >= len)
{
size_t unread = buf_unread(sbuf);
Expand All @@ -2426,7 +2427,6 @@ ssize_t netplay_recv(struct socket_buffer *sbuf, int sockfd,
if (sbuf->read >= sbuf->bufsz)
sbuf->read = 0;
recvd = len;

}
else if (unread > 0)
{
Expand All @@ -2442,8 +2442,8 @@ ssize_t netplay_recv(struct socket_buffer *sbuf, int sockfd,
else
{
/* Our read goes around the edge */
size_t chunka = sbuf->bufsz - sbuf->read;
size_t chunkb = ((len - chunka) > sbuf->end) ? sbuf->end :
size_t chunka = sbuf->bufsz - sbuf->read;
size_t chunkb = ((len - chunka) > sbuf->end) ? sbuf->end :
(len - chunka);

memcpy(buf, sbuf->data + sbuf->read, chunka);
Expand Down

0 comments on commit b59624a

Please sign in to comment.