aboutsummaryrefslogtreecommitdiff
path: root/src/util/disk.c
diff options
context:
space:
mode:
authorLRN <lrn1986@gmail.com>2015-01-24 23:01:22 +0000
committerLRN <lrn1986@gmail.com>2015-01-24 23:01:22 +0000
commita1193adca1ddba0f6ac1c58154ae8377225063a3 (patch)
treed2921ab5cb7376337e8a6be82a1d3954d80582a0 /src/util/disk.c
parent868ca61cf561f8902b1088710edcc60b96f91df5 (diff)
downloadgnunet-a1193adca1ddba0f6ac1c58154ae8377225063a3.tar.gz
gnunet-a1193adca1ddba0f6ac1c58154ae8377225063a3.zip
Add support for selecting on W32 events
Diffstat (limited to 'src/util/disk.c')
-rw-r--r--src/util/disk.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/util/disk.c b/src/util/disk.c
index 6753d8141..25a01aba6 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -854,7 +854,7 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
854#ifdef MINGW 854#ifdef MINGW
855 DWORD bytes_read; 855 DWORD bytes_read;
856 856
857 if (h->type != GNUNET_DISK_HANLDE_TYPE_PIPE) 857 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
858 { 858 {
859 if (!ReadFile (h->h, result, len, &bytes_read, NULL)) 859 if (!ReadFile (h->h, result, len, &bytes_read, NULL))
860 { 860 {
@@ -862,7 +862,7 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
862 return GNUNET_SYSERR; 862 return GNUNET_SYSERR;
863 } 863 }
864 } 864 }
865 else 865 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
866 { 866 {
867 if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead)) 867 if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
868 { 868 {
@@ -877,6 +877,10 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
877 } 877 }
878 LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes from pipe\n", bytes_read); 878 LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes from pipe\n", bytes_read);
879 } 879 }
880 else
881 {
882 bytes_read = 0;
883 }
880 return bytes_read; 884 return bytes_read;
881#else 885#else
882 return read (h->fd, result, len); 886 return read (h->fd, result, len);
@@ -908,7 +912,7 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
908#ifdef MINGW 912#ifdef MINGW
909 DWORD bytes_read; 913 DWORD bytes_read;
910 914
911 if (h->type != GNUNET_DISK_HANLDE_TYPE_PIPE) 915 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
912 { 916 {
913 if (!ReadFile (h->h, result, len, &bytes_read, NULL)) 917 if (!ReadFile (h->h, result, len, &bytes_read, NULL))
914 { 918 {
@@ -916,7 +920,7 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
916 return GNUNET_SYSERR; 920 return GNUNET_SYSERR;
917 } 921 }
918 } 922 }
919 else 923 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
920 { 924 {
921 if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead)) 925 if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
922 { 926 {
@@ -937,6 +941,10 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
937 } 941 }
938 LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytes_read); 942 LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytes_read);
939 } 943 }
944 else
945 {
946 bytes_read = 0;
947 }
940 return bytes_read; 948 return bytes_read;
941#else 949#else
942 int flags; 950 int flags;
@@ -1005,7 +1013,7 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
1005#ifdef MINGW 1013#ifdef MINGW
1006 DWORD bytes_written; 1014 DWORD bytes_written;
1007 1015
1008 if (h->type != GNUNET_DISK_HANLDE_TYPE_PIPE) 1016 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
1009 { 1017 {
1010 if (!WriteFile (h->h, buffer, n, &bytes_written, NULL)) 1018 if (!WriteFile (h->h, buffer, n, &bytes_written, NULL))
1011 { 1019 {
@@ -1013,7 +1021,7 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
1013 return GNUNET_SYSERR; 1021 return GNUNET_SYSERR;
1014 } 1022 }
1015 } 1023 }
1016 else 1024 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
1017 { 1025 {
1018 LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n); 1026 LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n);
1019 if (!WriteFile (h->h, buffer, n, &bytes_written, h->oOverlapWrite)) 1027 if (!WriteFile (h->h, buffer, n, &bytes_written, h->oOverlapWrite))
@@ -1062,6 +1070,10 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
1062 } 1070 }
1063 LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytes_written); 1071 LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytes_written);
1064 } 1072 }
1073 else
1074 {
1075 bytes_written = 0;
1076 }
1065 return bytes_written; 1077 return bytes_written;
1066#else 1078#else
1067 return write (h->fd, buffer, n); 1079 return write (h->fd, buffer, n);
@@ -1899,6 +1911,15 @@ GNUNET_DISK_get_handle_from_w32_handle (HANDLE osfh)
1899 case FILE_TYPE_PIPE: 1911 case FILE_TYPE_PIPE:
1900 ftype = GNUNET_DISK_HANLDE_TYPE_PIPE; 1912 ftype = GNUNET_DISK_HANLDE_TYPE_PIPE;
1901 break; 1913 break;
1914 case FILE_TYPE_UNKNOWN:
1915 if (GetLastError () == NO_ERROR)
1916 {
1917 if (0 != ResetEvent (osfh))
1918 ftype = GNUNET_DISK_HANLDE_TYPE_EVENT;
1919 }
1920 else
1921 return NULL;
1922 break;
1902 default: 1923 default:
1903 return NULL; 1924 return NULL;
1904 } 1925 }