AmendHub

Download:

jcs

/

subtext

/

amendments

/

269

folder: Only yield every other SHA1 chunk read

Our reads are relatively small, so this will speed up calculation
without affecting other users/threads too heavily.
 
Also move around some lines of code that made more sense while
debugging the ZModem issue.

jcs made amendment 269 over 2 years ago
--- folder.c Sun Oct 2 17:08:49 2022 +++ folder.c Sun Nov 6 21:13:05 2022 @@ -446,14 +446,14 @@ folder_upload(struct session *s, struct folder *folder goto file_upload_cancel; } + strlcpy(file.filename, zs->file_name, sizeof(file.filename)); + file.size = sb.st_size; + session_printf(s, "Successfully received file {{B}}%s{{/B}} of size " "{{B}}%ld{{/B}} byte%s.\r\n", - zs->file_name, zs->file_size, zs->file_size == 1 ? "" : "s"); + file.filename, file.size, file.size == 1 ? "" : "s"); session_pause_return(s, '\r', "to continue..."); - strlcpy(file.filename, zs->file_name, sizeof(file.filename)); - file.size = sb.st_size; - session_logf(s, "[%s] Received uploaded file %s of size %ld", folder->name, file.filename, file.size); @@ -463,19 +463,20 @@ folder_upload(struct session *s, struct folder *folder session_printf(s, "Calculating SHA1 checksum of uploaded file..."); session_flush(s); - SHA1Init(&sha1); data = xmalloc(1024, "folder_upload data"); + SHA1Init(&sha1); fp = fopen(upload_path, "rb"); - while (fp && !feof(fp)) { + for (n = 1; fp && !feof(fp); n++) { size = fread(data, 1024, 1, fp); SHA1Update(&sha1, (const u_int8_t *)data, size); - uthread_yield(); + if (n % 2 == 0) + uthread_yield(); } + SHA1End(&sha1, (char *)&file.sha1_checksum); if (fp) fclose(fp); xfree(&data); - SHA1End(&sha1, (char *)&file.sha1_checksum); session_printf(s, "done.\r\n\r\n"); session_flush(s); session_printf(s, "{{B}}Uploaded By:{{/B}} %s\r\n",