From 5b3dd70ac37ed5854309173afeda78737fd6bd1c Mon Sep 17 00:00:00 2001 From: gblues Date: Sun, 6 May 2018 19:08:32 -0700 Subject: [PATCH] Use a different packet size == DETAILS We had some disagreement on what packet size to use. The maximum packet size varies depending on the actual network hardware in use; the typical Ethernet value is relatively safe, but not 100% compatible. RFC 791 does, however, define a minimum datagram size that all IP hosts must be able to handle--and it's large enough for our needs, since we're generally not writing more than maybe 100 bytes at a time anyway. I also did a little bit of cleanup for readability. --- frontend/drivers/platform_wiiu.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/frontend/drivers/platform_wiiu.c b/frontend/drivers/platform_wiiu.c index 3a47fb576f..1960e12ec3 100644 --- a/frontend/drivers/platform_wiiu.c +++ b/frontend/drivers/platform_wiiu.c @@ -589,6 +589,11 @@ void net_print_exp(const char *str) sendto(wiiu_log_socket, str, strlen(str), 0, (struct sockaddr *)&broadcast, sizeof(broadcast)); } +/* RFC 791 specifies that any IP host must be able to receive a datagram of 576 bytes. + * Since we're generally never logging more than a line or two's worth of data (~100 bytes) + * this is a reasonable size for our use. */ +#define DGRAM_SIZE 576 + static ssize_t wiiu_log_write(struct _reent *r, void *fd, const char *ptr, size_t len) { if( wiiu_log_socket < 0) @@ -599,19 +604,19 @@ static ssize_t wiiu_log_write(struct _reent *r, void *fd, const char *ptr, size_ wiiu_log_lock = 1; - int ret; + int sent; int remaining = len; while(remaining > 0) { - int block = remaining < 1472 ? remaining : 1472; - ret = sendto(wiiu_log_socket, ptr, block, 0, (struct sockaddr *)&broadcast, sizeof(broadcast)); + int block = remaining < DGRAM_SIZE ? remaining : DGRAM_SIZE; + sent = sendto(wiiu_log_socket, ptr, block, 0, (struct sockaddr *)&broadcast, sizeof(broadcast)); - if(ret < 0) + if(sent < 0) break; - remaining -= ret; - ptr += ret; + remaining -= sent; + ptr += sent; } wiiu_log_lock = 0;