mirror of
https://github.com/libretro/RetroArch
synced 2025-03-28 19:20:35 +00:00
Added packet buffer resizing to cope with initialization quirks.
This commit is contained in:
parent
36a93e5697
commit
1214541410
@ -1204,6 +1204,7 @@ static void announce_nat_traversal(netplay_t *netplay)
|
||||
bool netplay_try_init_serialization(netplay_t *netplay)
|
||||
{
|
||||
retro_ctx_serialize_info_t serial_info;
|
||||
size_t packet_buffer_size;
|
||||
|
||||
if (netplay->state_size)
|
||||
return true;
|
||||
@ -1222,6 +1223,14 @@ bool netplay_try_init_serialization(netplay_t *netplay)
|
||||
/* Once initialized, we no longer exhibit this quirk */
|
||||
netplay->quirks &= ~((uint64_t) NETPLAY_QUIRK_INITIALIZATION);
|
||||
|
||||
/* Now we need a different packet buffer size because we actually know our
|
||||
* state size */
|
||||
/* FIXME: Duplication */
|
||||
packet_buffer_size = netplay->state_size + netplay->stall_frames *
|
||||
WORDS_PER_FRAME + (netplay->stall_frames+1)*3;
|
||||
netplay_resize_socket_buffer(&netplay->send_packet_buffer, packet_buffer_size);
|
||||
netplay_resize_socket_buffer(&netplay->recv_packet_buffer, packet_buffer_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,40 @@ bool netplay_init_socket_buffer(struct socket_buffer *sbuf, size_t size)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netplay_resize_socket_buffer(struct socket_buffer *sbuf, size_t newsize)
|
||||
{
|
||||
unsigned char *newdata = malloc(newsize);
|
||||
if (newdata == NULL)
|
||||
return false;
|
||||
|
||||
/* Copy in the old data */
|
||||
if (sbuf->end < sbuf->start)
|
||||
{
|
||||
memcpy(newdata, sbuf->data + sbuf->start, sbuf->bufsz - sbuf->start);
|
||||
memcpy(newdata + sbuf->bufsz - sbuf->start, sbuf->data, sbuf->end);
|
||||
}
|
||||
else if (sbuf->end > sbuf->start)
|
||||
{
|
||||
memcpy(newdata, sbuf->data + sbuf->start, sbuf->end - sbuf->start);
|
||||
}
|
||||
|
||||
/* Adjust our read offset */
|
||||
if (sbuf->read < sbuf->start)
|
||||
sbuf->read += sbuf->bufsz - sbuf->start;
|
||||
else
|
||||
sbuf->read -= sbuf->start;
|
||||
|
||||
/* Adjust start and end */
|
||||
sbuf->end = buf_used(sbuf);
|
||||
sbuf->start = 0;
|
||||
|
||||
/* Free the old one and replace it with the new one */
|
||||
free(sbuf->data);
|
||||
sbuf->data = newdata;
|
||||
sbuf->bufsz = newsize;
|
||||
return true;
|
||||
}
|
||||
|
||||
void netplay_deinit_socket_buffer(struct socket_buffer *sbuf)
|
||||
{
|
||||
if (sbuf->data)
|
||||
|
@ -280,6 +280,8 @@ bool netplay_lan_ad_server(netplay_t *netplay);
|
||||
|
||||
bool netplay_init_socket_buffer(struct socket_buffer *sbuf, size_t size);
|
||||
|
||||
bool netplay_resize_socket_buffer(struct socket_buffer *sbuf, size_t newsize);
|
||||
|
||||
void netplay_deinit_socket_buffer(struct socket_buffer *sbuf);
|
||||
|
||||
void netplay_clear_socket_buffer(struct socket_buffer *sbuf);
|
||||
|
Loading…
x
Reference in New Issue
Block a user