Skip to content

Commit

Permalink
Enabled using setvbuf with adjustments, improves netloader perf. Fixe…
Browse files Browse the repository at this point in the history
…d issue with large-chunksize, chunksize is now uint32_t and initialized to 0. Minor other change.
  • Loading branch information
yellows8 committed Aug 8, 2019
1 parent ea4db4f commit fa3d93d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions common/netloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit fa3d93d

Please sign in to comment.