diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-14 18:31:25 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-14 18:31:25 +0000 |
commit | c1e66b2a4e2ccf3fc4f3396d97254fa058c6ae73 (patch) | |
tree | cd6ed8e6dcb2963c7183c300209a71e104db3a11 /src | |
parent | 85967c4d4bd03d68a677f6e8023b192b8b4453f5 (diff) | |
download | gnunet-c1e66b2a4e2ccf3fc4f3396d97254fa058c6ae73.tar.gz gnunet-c1e66b2a4e2ccf3fc4f3396d97254fa058c6ae73.zip |
-LRN: fix pipe writing and progress write
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/fs_dirmetascan.c | 50 | ||||
-rw-r--r-- | src/util/disk.c | 70 |
2 files changed, 88 insertions, 32 deletions
diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c index 372579ccb..880710356 100644 --- a/src/fs/fs_dirmetascan.c +++ b/src/fs/fs_dirmetascan.c | |||
@@ -346,61 +346,61 @@ write_progress (struct AddDirContext *adc, const char *filename, | |||
346 | char is_directory, enum GNUNET_DirScannerProgressUpdateReason reason) | 346 | char is_directory, enum GNUNET_DirScannerProgressUpdateReason reason) |
347 | { | 347 | { |
348 | size_t filename_len; | 348 | size_t filename_len; |
349 | size_t wr; | 349 | ssize_t wr; |
350 | size_t total_write; | 350 | size_t total_write; |
351 | if ((adc->do_stop || should_stop (adc)) && reason != GNUNET_DIR_SCANNER_ASKED_TO_STOP | 351 | if ((adc->do_stop || should_stop (adc)) && reason != GNUNET_DIR_SCANNER_ASKED_TO_STOP |
352 | && reason != GNUNET_DIR_SCANNER_FINISHED) | 352 | && reason != GNUNET_DIR_SCANNER_FINISHED) |
353 | return 1; | 353 | return 1; |
354 | total_write = wr = GNUNET_DISK_file_write (adc->progress_write, | 354 | total_write = 0; |
355 | &reason, sizeof (reason)); | 355 | wr = 1; |
356 | while (wr > 0 && total_write < sizeof (reason)) | 356 | while ((wr > 0 || errno == EAGAIN) && total_write < sizeof (reason)) |
357 | { | 357 | { |
358 | total_write = wr = GNUNET_DISK_file_write (adc->progress_write, | 358 | wr = GNUNET_DISK_file_write (adc->progress_write, |
359 | &((char *)&reason)[total_write], sizeof (reason) - total_write); | 359 | &((char *)&reason)[total_write], sizeof (reason) - total_write); |
360 | if (wr > 0) | 360 | if (wr > 0) |
361 | total_write += wr; | 361 | total_write += wr; |
362 | } | 362 | } |
363 | if (sizeof (reason) != wr) | 363 | if (sizeof (reason) != total_write) |
364 | return 1; | 364 | return adc->do_stop = 1; |
365 | if (filename) | 365 | if (filename) |
366 | filename_len = strlen (filename) + 1; | 366 | filename_len = strlen (filename) + 1; |
367 | else | 367 | else |
368 | filename_len = 0; | 368 | filename_len = 0; |
369 | total_write = wr = GNUNET_DISK_file_write (adc->progress_write, | 369 | total_write = 0; |
370 | &filename_len, sizeof (size_t)); | 370 | wr = 1; |
371 | while (wr > 0 && total_write < sizeof (size_t)) | 371 | while ((wr > 0 || errno == EAGAIN) && total_write < sizeof (size_t)) |
372 | { | 372 | { |
373 | total_write = wr = GNUNET_DISK_file_write (adc->progress_write, | 373 | wr = GNUNET_DISK_file_write (adc->progress_write, |
374 | &((char *)&filename_len)[total_write], sizeof (size_t) - total_write); | 374 | &((char *)&filename_len)[total_write], sizeof (size_t) - total_write); |
375 | if (wr > 0) | 375 | if (wr > 0) |
376 | total_write += wr; | 376 | total_write += wr; |
377 | } | 377 | } |
378 | if (sizeof (size_t) != wr) | 378 | if (sizeof (size_t) != total_write) |
379 | return 1; | 379 | return adc->do_stop = 1; |
380 | if (filename) | 380 | if (filename) |
381 | { | 381 | { |
382 | total_write = wr = GNUNET_DISK_file_write (adc->progress_write, | 382 | total_write = 0; |
383 | filename, filename_len); | 383 | wr = 1; |
384 | while (wr > 0 && total_write < filename_len) | 384 | while ((wr > 0 || errno == EAGAIN) && total_write < filename_len) |
385 | { | 385 | { |
386 | total_write = wr = GNUNET_DISK_file_write (adc->progress_write, | 386 | wr = GNUNET_DISK_file_write (adc->progress_write, |
387 | &((char *)filename)[total_write], filename_len - total_write); | 387 | &((char *)filename)[total_write], filename_len - total_write); |
388 | if (wr > 0) | 388 | if (wr > 0) |
389 | total_write += wr; | 389 | total_write += wr; |
390 | } | 390 | } |
391 | if (filename_len != wr) | 391 | if (filename_len != total_write) |
392 | return 1; | 392 | return adc->do_stop = 1; |
393 | total_write = wr = GNUNET_DISK_file_write (adc->progress_write, | 393 | total_write = 0; |
394 | &is_directory, sizeof (char)); | 394 | wr = 1; |
395 | while (wr > 0 && total_write < sizeof (char)) | 395 | while ((wr > 0 || errno == EAGAIN) && total_write < sizeof (char)) |
396 | { | 396 | { |
397 | total_write = wr = GNUNET_DISK_file_write (adc->progress_write, | 397 | wr = GNUNET_DISK_file_write (adc->progress_write, |
398 | &((char *)&is_directory)[total_write], sizeof (char) - total_write); | 398 | &((char *)&is_directory)[total_write], sizeof (char) - total_write); |
399 | if (wr > 0) | 399 | if (wr > 0) |
400 | total_write += wr; | 400 | total_write += wr; |
401 | } | 401 | } |
402 | if (sizeof (char) != wr) | 402 | if (sizeof (char) != total_write) |
403 | return 1; | 403 | return adc->do_stop = 1; |
404 | } | 404 | } |
405 | return 0; | 405 | return 0; |
406 | } | 406 | } |
diff --git a/src/util/disk.c b/src/util/disk.c index 8d1fe3c12..eb707fd62 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -718,15 +718,27 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result, | |||
718 | } | 718 | } |
719 | else | 719 | else |
720 | { | 720 | { |
721 | if (!ReadFile (h->h, result, len, NULL, h->oOverlapRead)) | 721 | #if DEBUG_PIPE |
722 | LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to read\n"); | ||
723 | #endif | ||
724 | if (!ReadFile (h->h, result, len, &bytesRead, h->oOverlapRead)) | ||
722 | { | 725 | { |
723 | if (GetLastError () != ERROR_IO_PENDING) | 726 | if (GetLastError () != ERROR_IO_PENDING) |
724 | { | 727 | { |
728 | #if DEBUG_PIPE | ||
729 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error reading from pipe: %u\n", GetLastError ()); | ||
730 | #endif | ||
725 | SetErrnoFromWinError (GetLastError ()); | 731 | SetErrnoFromWinError (GetLastError ()); |
726 | return GNUNET_SYSERR; | 732 | return GNUNET_SYSERR; |
727 | } | 733 | } |
734 | #if DEBUG_PIPE | ||
735 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); | ||
736 | #endif | ||
737 | GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE); | ||
728 | } | 738 | } |
729 | GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE); | 739 | #if DEBUG_PIPE |
740 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytesRead); | ||
741 | #endif | ||
730 | } | 742 | } |
731 | return bytesRead; | 743 | return bytesRead; |
732 | #else | 744 | #else |
@@ -790,23 +802,67 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h, | |||
790 | else | 802 | else |
791 | { | 803 | { |
792 | #if DEBUG_PIPE | 804 | #if DEBUG_PIPE |
793 | LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write\n"); | 805 | LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n); |
794 | #endif | 806 | #endif |
795 | if (!WriteFile (h->h, buffer, n, NULL, h->oOverlapWrite)) | 807 | if (!WriteFile (h->h, buffer, n, &bytesWritten, h->oOverlapWrite)) |
796 | { | 808 | { |
797 | if (GetLastError () != ERROR_IO_PENDING) | 809 | if (GetLastError () != ERROR_IO_PENDING) |
798 | { | 810 | { |
799 | SetErrnoFromWinError (GetLastError ()); | 811 | SetErrnoFromWinError (GetLastError ()); |
800 | #if DEBUG_PIPE | 812 | #if DEBUG_PIPE |
801 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe\n"); | 813 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", |
814 | GetLastError ()); | ||
815 | #endif | ||
816 | return GNUNET_SYSERR; | ||
817 | } | ||
818 | #if DEBUG_PIPE | ||
819 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); | ||
820 | #endif | ||
821 | if (!GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE)) | ||
822 | { | ||
823 | SetErrnoFromWinError (GetLastError ()); | ||
824 | #if DEBUG_PIPE | ||
825 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
826 | "Error getting overlapped result while writing to pipe: %u\n", | ||
827 | GetLastError ()); | ||
828 | #endif | ||
829 | return GNUNET_SYSERR; | ||
830 | } | ||
831 | } | ||
832 | else | ||
833 | { | ||
834 | DWORD ovr; | ||
835 | if (!GetOverlappedResult (h->h, h->oOverlapWrite, &ovr, TRUE)) | ||
836 | { | ||
837 | #if DEBUG_PIPE | ||
838 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
839 | "Error getting control overlapped result while writing to pipe: %u\n", | ||
840 | GetLastError ()); | ||
841 | #endif | ||
842 | } | ||
843 | else | ||
844 | { | ||
845 | #if DEBUG_PIPE | ||
846 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
847 | "Wrote %u bytes (ovr says %u), picking the greatest\n", | ||
848 | bytesWritten, ovr); | ||
849 | #endif | ||
850 | } | ||
851 | } | ||
852 | if (bytesWritten == 0) | ||
853 | { | ||
854 | if (n > 0) | ||
855 | { | ||
856 | #if DEBUG_PIPE | ||
857 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes, returning -1 with EAGAIN\n", bytesWritten); | ||
802 | #endif | 858 | #endif |
859 | errno = EAGAIN; | ||
803 | return GNUNET_SYSERR; | 860 | return GNUNET_SYSERR; |
804 | } | 861 | } |
805 | } | 862 | } |
806 | #if DEBUG_PIPE | 863 | #if DEBUG_PIPE |
807 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); | 864 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytesWritten); |
808 | #endif | 865 | #endif |
809 | GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE); | ||
810 | } | 866 | } |
811 | return bytesWritten; | 867 | return bytesWritten; |
812 | #else | 868 | #else |