diff options
Diffstat (limited to 'src/util/disk.c')
-rw-r--r-- | src/util/disk.c | 73 |
1 files changed, 3 insertions, 70 deletions
diff --git a/src/util/disk.c b/src/util/disk.c index cebf6d033..667e350d9 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -40,10 +40,6 @@ | |||
40 | 40 | ||
41 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) | 41 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) |
42 | 42 | ||
43 | #define DEBUG_NPIPE GNUNET_EXTRA_LOGGING | ||
44 | |||
45 | #define DEBUG_PIPE GNUNET_EXTRA_LOGGING | ||
46 | |||
47 | /** | 43 | /** |
48 | * Block size for IO for copying files. | 44 | * Block size for IO for copying files. |
49 | */ | 45 | */ |
@@ -732,27 +728,18 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result, | |||
732 | } | 728 | } |
733 | else | 729 | else |
734 | { | 730 | { |
735 | #if DEBUG_PIPE | ||
736 | LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to read\n"); | ||
737 | #endif | ||
738 | if (!ReadFile (h->h, result, len, &bytesRead, h->oOverlapRead)) | 731 | if (!ReadFile (h->h, result, len, &bytesRead, h->oOverlapRead)) |
739 | { | 732 | { |
740 | if (GetLastError () != ERROR_IO_PENDING) | 733 | if (GetLastError () != ERROR_IO_PENDING) |
741 | { | 734 | { |
742 | #if DEBUG_PIPE | ||
743 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error reading from pipe: %u\n", GetLastError ()); | 735 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error reading from pipe: %u\n", GetLastError ()); |
744 | #endif | ||
745 | SetErrnoFromWinError (GetLastError ()); | 736 | SetErrnoFromWinError (GetLastError ()); |
746 | return GNUNET_SYSERR; | 737 | return GNUNET_SYSERR; |
747 | } | 738 | } |
748 | #if DEBUG_PIPE | ||
749 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); | 739 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); |
750 | #endif | ||
751 | GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE); | 740 | GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE); |
752 | } | 741 | } |
753 | #if DEBUG_PIPE | 742 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes from pipe\n", bytesRead); |
754 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytesRead); | ||
755 | #endif | ||
756 | } | 743 | } |
757 | return bytesRead; | 744 | return bytesRead; |
758 | #else | 745 | #else |
@@ -794,33 +781,24 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h, | |||
794 | } | 781 | } |
795 | else | 782 | else |
796 | { | 783 | { |
797 | #if DEBUG_PIPE | ||
798 | LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe, trying to read\n"); | ||
799 | #endif | ||
800 | if (!ReadFile (h->h, result, len, &bytesRead, h->oOverlapRead)) | 784 | if (!ReadFile (h->h, result, len, &bytesRead, h->oOverlapRead)) |
801 | { | 785 | { |
802 | if (GetLastError () != ERROR_IO_PENDING) | 786 | if (GetLastError () != ERROR_IO_PENDING) |
803 | { | 787 | { |
804 | #if DEBUG_PIPE | ||
805 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error reading from pipe: %u\n", GetLastError ()); | 788 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error reading from pipe: %u\n", GetLastError ()); |
806 | #endif | ||
807 | SetErrnoFromWinError (GetLastError ()); | 789 | SetErrnoFromWinError (GetLastError ()); |
808 | return GNUNET_SYSERR; | 790 | return GNUNET_SYSERR; |
809 | } | 791 | } |
810 | else | 792 | else |
811 | { | 793 | { |
812 | #if DEBUG_PIPE | ||
813 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 794 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
814 | "ReadFile() queued a read, cancelling\n"); | 795 | "ReadFile() queued a read, cancelling\n"); |
815 | #endif | ||
816 | CancelIo (h->h); | 796 | CancelIo (h->h); |
817 | errno = EAGAIN; | 797 | errno = EAGAIN; |
818 | return GNUNET_SYSERR; | 798 | return GNUNET_SYSERR; |
819 | } | 799 | } |
820 | } | 800 | } |
821 | #if DEBUG_PIPE | ||
822 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytesRead); | 801 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytesRead); |
823 | #endif | ||
824 | } | 802 | } |
825 | return bytesRead; | 803 | return bytesRead; |
826 | #else | 804 | #else |
@@ -893,31 +871,23 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h, | |||
893 | } | 871 | } |
894 | else | 872 | else |
895 | { | 873 | { |
896 | #if DEBUG_PIPE | ||
897 | LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n); | 874 | LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n); |
898 | #endif | ||
899 | if (!WriteFile (h->h, buffer, n, &bytesWritten, h->oOverlapWrite)) | 875 | if (!WriteFile (h->h, buffer, n, &bytesWritten, h->oOverlapWrite)) |
900 | { | 876 | { |
901 | if (GetLastError () != ERROR_IO_PENDING) | 877 | if (GetLastError () != ERROR_IO_PENDING) |
902 | { | 878 | { |
903 | SetErrnoFromWinError (GetLastError ()); | 879 | SetErrnoFromWinError (GetLastError ()); |
904 | #if DEBUG_PIPE | ||
905 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", | 880 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", |
906 | GetLastError ()); | 881 | GetLastError ()); |
907 | #endif | ||
908 | return GNUNET_SYSERR; | 882 | return GNUNET_SYSERR; |
909 | } | 883 | } |
910 | #if DEBUG_PIPE | ||
911 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); | 884 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); |
912 | #endif | ||
913 | if (!GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE)) | 885 | if (!GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE)) |
914 | { | 886 | { |
915 | SetErrnoFromWinError (GetLastError ()); | 887 | SetErrnoFromWinError (GetLastError ()); |
916 | #if DEBUG_PIPE | ||
917 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 888 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
918 | "Error getting overlapped result while writing to pipe: %u\n", | 889 | "Error getting overlapped result while writing to pipe: %u\n", |
919 | GetLastError ()); | 890 | GetLastError ()); |
920 | #endif | ||
921 | return GNUNET_SYSERR; | 891 | return GNUNET_SYSERR; |
922 | } | 892 | } |
923 | } | 893 | } |
@@ -926,35 +896,27 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h, | |||
926 | DWORD ovr; | 896 | DWORD ovr; |
927 | if (!GetOverlappedResult (h->h, h->oOverlapWrite, &ovr, TRUE)) | 897 | if (!GetOverlappedResult (h->h, h->oOverlapWrite, &ovr, TRUE)) |
928 | { | 898 | { |
929 | #if DEBUG_PIPE | ||
930 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 899 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
931 | "Error getting control overlapped result while writing to pipe: %u\n", | 900 | "Error getting control overlapped result while writing to pipe: %u\n", |
932 | GetLastError ()); | 901 | GetLastError ()); |
933 | #endif | ||
934 | } | 902 | } |
935 | else | 903 | else |
936 | { | 904 | { |
937 | #if DEBUG_PIPE | ||
938 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 905 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
939 | "Wrote %u bytes (ovr says %u), picking the greatest\n", | 906 | "Wrote %u bytes (ovr says %u), picking the greatest\n", |
940 | bytesWritten, ovr); | 907 | bytesWritten, ovr); |
941 | #endif | ||
942 | } | 908 | } |
943 | } | 909 | } |
944 | if (bytesWritten == 0) | 910 | if (bytesWritten == 0) |
945 | { | 911 | { |
946 | if (n > 0) | 912 | if (n > 0) |
947 | { | 913 | { |
948 | #if DEBUG_PIPE | ||
949 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes, returning -1 with EAGAIN\n", bytesWritten); | 914 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes, returning -1 with EAGAIN\n", bytesWritten); |
950 | #endif | ||
951 | errno = EAGAIN; | 915 | errno = EAGAIN; |
952 | return GNUNET_SYSERR; | 916 | return GNUNET_SYSERR; |
953 | } | 917 | } |
954 | } | 918 | } |
955 | #if DEBUG_PIPE | ||
956 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytesWritten); | 919 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytesWritten); |
957 | #endif | ||
958 | } | 920 | } |
959 | return bytesWritten; | 921 | return bytesWritten; |
960 | #else | 922 | #else |
@@ -983,37 +945,27 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h, | |||
983 | #ifdef MINGW | 945 | #ifdef MINGW |
984 | DWORD bytesWritten; | 946 | DWORD bytesWritten; |
985 | /* We do a non-overlapped write, which is as blocking as it gets */ | 947 | /* We do a non-overlapped write, which is as blocking as it gets */ |
986 | #if DEBUG_PIPE | ||
987 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing %u bytes\n", n); | 948 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing %u bytes\n", n); |
988 | #endif | ||
989 | if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) | 949 | if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) |
990 | { | 950 | { |
991 | SetErrnoFromWinError (GetLastError ()); | 951 | SetErrnoFromWinError (GetLastError ()); |
992 | #if DEBUG_PIPE | ||
993 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", | 952 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", |
994 | GetLastError ()); | 953 | GetLastError ()); |
995 | #endif | ||
996 | return GNUNET_SYSERR; | 954 | return GNUNET_SYSERR; |
997 | } | 955 | } |
998 | if (bytesWritten == 0 && n > 0) | 956 | if (bytesWritten == 0 && n > 0) |
999 | { | 957 | { |
1000 | #if DEBUG_PIPE | ||
1001 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for pipe to clean\n"); | 958 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for pipe to clean\n"); |
1002 | #endif | ||
1003 | WaitForSingleObject (h->h, INFINITE); | 959 | WaitForSingleObject (h->h, INFINITE); |
1004 | if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) | 960 | if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) |
1005 | { | 961 | { |
1006 | SetErrnoFromWinError (GetLastError ()); | 962 | SetErrnoFromWinError (GetLastError ()); |
1007 | #if DEBUG_PIPE | ||
1008 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", | 963 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", |
1009 | GetLastError ()); | 964 | GetLastError ()); |
1010 | #endif | ||
1011 | return GNUNET_SYSERR; | 965 | return GNUNET_SYSERR; |
1012 | } | 966 | } |
1013 | } | 967 | } |
1014 | #if DEBUG_PIPE | ||
1015 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytesWritten); | 968 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytesWritten); |
1016 | #endif | ||
1017 | return bytesWritten; | 969 | return bytesWritten; |
1018 | #else | 970 | #else |
1019 | int flags; | 971 | int flags; |
@@ -2021,10 +1973,8 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr, | |||
2021 | 1973 | ||
2022 | snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld", | 1974 | snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld", |
2023 | getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id)); | 1975 | getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id)); |
2024 | #if DEBUG_PIPE | ||
2025 | LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe: name = %s, size = %lu\n", | 1976 | LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe: name = %s, size = %lu\n", |
2026 | pipename, psize); | 1977 | pipename, psize); |
2027 | #endif | ||
2028 | /* Use CreateNamedPipe instead of CreatePipe, because the latter | 1978 | /* Use CreateNamedPipe instead of CreatePipe, because the latter |
2029 | * returns a write handle that does not permit FILE_READ_ATTRIBUTES | 1979 | * returns a write handle that does not permit FILE_READ_ATTRIBUTES |
2030 | * access, on versions of win32 earlier than WinXP SP2. | 1980 | * access, on versions of win32 earlier than WinXP SP2. |
@@ -2041,9 +1991,7 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr, | |||
2041 | 1991 | ||
2042 | if (read_pipe != INVALID_HANDLE_VALUE) | 1992 | if (read_pipe != INVALID_HANDLE_VALUE) |
2043 | { | 1993 | { |
2044 | #if DEBUG_PIPE | ||
2045 | LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", read_pipe); | 1994 | LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", read_pipe); |
2046 | #endif | ||
2047 | break; | 1995 | break; |
2048 | } | 1996 | } |
2049 | 1997 | ||
@@ -2054,33 +2002,24 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr, | |||
2054 | case ERROR_PIPE_BUSY: | 2002 | case ERROR_PIPE_BUSY: |
2055 | /* The pipe is already open with compatible parameters. | 2003 | /* The pipe is already open with compatible parameters. |
2056 | * Pick a new name and retry. */ | 2004 | * Pick a new name and retry. */ |
2057 | #if DEBUG_PIPE | ||
2058 | LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n"); | 2005 | LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n"); |
2059 | #endif | ||
2060 | continue; | 2006 | continue; |
2061 | case ERROR_ACCESS_DENIED: | 2007 | case ERROR_ACCESS_DENIED: |
2062 | /* The pipe is already open with incompatible parameters. | 2008 | /* The pipe is already open with incompatible parameters. |
2063 | * Pick a new name and retry. */ | 2009 | * Pick a new name and retry. */ |
2064 | #if DEBUG_PIPE | ||
2065 | LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n"); | 2010 | LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n"); |
2066 | #endif | ||
2067 | continue; | 2011 | continue; |
2068 | case ERROR_CALL_NOT_IMPLEMENTED: | 2012 | case ERROR_CALL_NOT_IMPLEMENTED: |
2069 | /* We are on an older Win9x platform without named pipes. | 2013 | /* We are on an older Win9x platform without named pipes. |
2070 | * Return an anonymous pipe as the best approximation. */ | 2014 | * Return an anonymous pipe as the best approximation. */ |
2071 | #if DEBUG_PIPE | ||
2072 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2015 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2073 | "CreateNamedPipe not implemented, resorting to " | 2016 | "CreateNamedPipe not implemented, resorting to " |
2074 | "CreatePipe: size = %lu\n", psize); | 2017 | "CreatePipe: size = %lu\n", psize); |
2075 | #endif | ||
2076 | if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize)) | 2018 | if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize)) |
2077 | { | 2019 | { |
2078 | #if DEBUG_PIPE | 2020 | LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p, write handle = %p\n", |
2079 | LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", | 2021 | *read_pipe_ptr, |
2080 | *read_pipe_ptr); | ||
2081 | LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", | ||
2082 | *write_pipe_ptr); | 2022 | *write_pipe_ptr); |
2083 | #endif | ||
2084 | return GNUNET_OK; | 2023 | return GNUNET_OK; |
2085 | } | 2024 | } |
2086 | err = GetLastError (); | 2025 | err = GetLastError (); |
@@ -2092,9 +2031,7 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr, | |||
2092 | } | 2031 | } |
2093 | /* NOTREACHED */ | 2032 | /* NOTREACHED */ |
2094 | } | 2033 | } |
2095 | #if DEBUG_PIPE | ||
2096 | LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile: name = %s\n", pipename); | 2034 | LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile: name = %s\n", pipename); |
2097 | #endif | ||
2098 | 2035 | ||
2099 | /* Open the named pipe for writing. | 2036 | /* Open the named pipe for writing. |
2100 | * Be sure to permit FILE_READ_ATTRIBUTES access. */ | 2037 | * Be sure to permit FILE_READ_ATTRIBUTES access. */ |
@@ -2107,15 +2044,11 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr, | |||
2107 | /* Failure. */ | 2044 | /* Failure. */ |
2108 | DWORD err = GetLastError (); | 2045 | DWORD err = GetLastError (); |
2109 | 2046 | ||
2110 | #if DEBUG_PIPE | ||
2111 | LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err); | 2047 | LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err); |
2112 | #endif | ||
2113 | CloseHandle (read_pipe); | 2048 | CloseHandle (read_pipe); |
2114 | return err; | 2049 | return err; |
2115 | } | 2050 | } |
2116 | #if DEBUG_PIPE | ||
2117 | LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", write_pipe); | 2051 | LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", write_pipe); |
2118 | #endif | ||
2119 | /* Success. */ | 2052 | /* Success. */ |
2120 | *read_pipe_ptr = read_pipe; | 2053 | *read_pipe_ptr = read_pipe; |
2121 | *write_pipe_ptr = write_pipe; | 2054 | *write_pipe_ptr = write_pipe; |