From fa3d93d6491c9e7df4107eda9e155e91b3fc923e Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 8 Aug 2019 17:55:56 -0400 Subject: [PATCH] Enabled using setvbuf with adjustments, improves netloader perf. Fixed issue with large-chunksize, chunksize is now uint32_t and initialized to 0. Minor other change. --- common/netloader.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/common/netloader.c b/common/netloader.c index 9624870e..471b03dc 100644 --- a/common/netloader.c +++ b/common/netloader.c @@ -274,7 +274,7 @@ static int decompress(int sock, FILE *fh, size_t filesize) { int ret; unsigned have; z_stream strm; - size_t chunksize; + uint32_t chunksize=0; /* allocate inflate state */ strm.zalloc = Z_NULL; @@ -306,7 +306,7 @@ static int decompress(int sock, FILE *fh, size_t filesize) { if (chunksize > sizeof(in)) { (void)inflateEnd(&strm); - netloader_error("Invalid chunk size.",0); + netloader_error("Invalid chunk size",chunksize); return Z_DATA_ERROR; } @@ -442,11 +442,18 @@ int loadnro(menuEntry_s *me, int sock, struct in_addr remote) { send(sock,(char *)&response,sizeof(response),0); + char *writebuffer = NULL; if (response == 0 ) { + writebuffer = malloc(FILE_BUFFER_SIZE); + if (writebuffer==NULL) { + netloader_error("Failed to allocate memory",ENOMEM); + response = -1; + } + else + setvbuf(file,writebuffer,_IOFBF, FILE_BUFFER_SIZE); + } - //char *writebuffer=malloc(FILE_BUFFER_SIZE); - //setvbuf(file,writebuffer,_IOFBF, FILE_BUFFER_SIZE); - + if (response == 0 ) { //printf("transferring %s\n%d bytes.\n", filename, filelen); if (decompress(sock,file,filelen)==Z_OK) { @@ -493,9 +500,9 @@ int loadnro(menuEntry_s *me, int sock, struct in_addr remote) { response = -1; } - //free(writebuffer); fflush(file); fclose(file); + free(writebuffer); if (response == -1) unlink(me->path); }