aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-14 18:31:25 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-14 18:31:25 +0000
commitc1e66b2a4e2ccf3fc4f3396d97254fa058c6ae73 (patch)
treecd6ed8e6dcb2963c7183c300209a71e104db3a11 /src/util
parent85967c4d4bd03d68a677f6e8023b192b8b4453f5 (diff)
downloadgnunet-c1e66b2a4e2ccf3fc4f3396d97254fa058c6ae73.tar.gz
gnunet-c1e66b2a4e2ccf3fc4f3396d97254fa058c6ae73.zip
-LRN: fix pipe writing and progress write
Diffstat (limited to 'src/util')
-rw-r--r--src/util/disk.c70
1 files changed, 63 insertions, 7 deletions
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