diff options
author | LRN <lrn1986@gmail.com> | 2015-01-24 23:01:22 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2015-01-24 23:01:22 +0000 |
commit | a1193adca1ddba0f6ac1c58154ae8377225063a3 (patch) | |
tree | d2921ab5cb7376337e8a6be82a1d3954d80582a0 /src | |
parent | 868ca61cf561f8902b1088710edcc60b96f91df5 (diff) | |
download | gnunet-a1193adca1ddba0f6ac1c58154ae8377225063a3.tar.gz gnunet-a1193adca1ddba0f6ac1c58154ae8377225063a3.zip |
Add support for selecting on W32 events
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_disk_lib.h | 5 | ||||
-rw-r--r-- | src/util/disk.c | 33 | ||||
-rw-r--r-- | src/util/network.c | 26 |
3 files changed, 53 insertions, 11 deletions
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index f14285f89..56c6dca41 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h | |||
@@ -36,6 +36,11 @@ struct GNUNET_DISK_PipeHandle; | |||
36 | enum GNUNET_FILE_Type | 36 | enum GNUNET_FILE_Type |
37 | { | 37 | { |
38 | /** | 38 | /** |
39 | * Handle represents an event. | ||
40 | */ | ||
41 | GNUNET_DISK_HANLDE_TYPE_EVENT, | ||
42 | |||
43 | /** | ||
39 | * Handle represents a file. | 44 | * Handle represents a file. |
40 | */ | 45 | */ |
41 | GNUNET_DISK_HANLDE_TYPE_FILE, | 46 | GNUNET_DISK_HANLDE_TYPE_FILE, |
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 | } |
diff --git a/src/util/network.c b/src/util/network.c index f2be1aab6..c2ba51d94 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -1725,15 +1725,26 @@ check_handles_status (struct GNUNET_NETWORK_FDSet *fds, int except) | |||
1725 | struct GNUNET_DISK_FileHandle *fh; | 1725 | struct GNUNET_DISK_FileHandle *fh; |
1726 | unsigned int roff; | 1726 | unsigned int roff; |
1727 | unsigned int woff; | 1727 | unsigned int woff; |
1728 | int is_pipe; | ||
1729 | 1728 | ||
1730 | for (woff = 0, roff = 0; roff < fds->handles_pos; roff++) | 1729 | for (woff = 0, roff = 0; roff < fds->handles_pos; roff++) |
1731 | { | 1730 | { |
1732 | fh = fds->handles[roff]; | 1731 | fh = fds->handles[roff]; |
1733 | is_pipe = fh->type == GNUNET_DISK_HANLDE_TYPE_PIPE; | 1732 | if (fh->type == GNUNET_DISK_HANLDE_TYPE_PIPE) |
1734 | if ((except && is_pipe && pipe_except_ready (fh)) || | 1733 | { |
1735 | (!except && (!is_pipe || pipe_read_ready (fh)))) | 1734 | if ((except && pipe_except_ready (fh)) || |
1736 | fds->handles[woff++] = fh; | 1735 | (!except && pipe_read_ready (fh))) |
1736 | fds->handles[woff++] = fh; | ||
1737 | } | ||
1738 | else if (fh->type == GNUNET_DISK_HANLDE_TYPE_FILE) | ||
1739 | { | ||
1740 | if (!except) | ||
1741 | fds->handles[woff++] = fh; | ||
1742 | } | ||
1743 | else | ||
1744 | { | ||
1745 | if (WAIT_OBJECT_0 == WaitForSingleObject (fh, 0)) | ||
1746 | fds->handles[woff++] = fh; | ||
1747 | } | ||
1737 | } | 1748 | } |
1738 | fds->handles_pos = woff; | 1749 | fds->handles_pos = woff; |
1739 | return woff; | 1750 | return woff; |
@@ -1951,6 +1962,11 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1951 | for (i = 0; i <rfds->handles_pos; i++) | 1962 | for (i = 0; i <rfds->handles_pos; i++) |
1952 | { | 1963 | { |
1953 | fh = rfds->handles[i]; | 1964 | fh = rfds->handles[i]; |
1965 | if (fh->type == GNUNET_DISK_HANLDE_TYPE_EVENT) | ||
1966 | { | ||
1967 | handle_array[nhandles++] = fh->h; | ||
1968 | continue; | ||
1969 | } | ||
1954 | if (fh->type != GNUNET_DISK_HANLDE_TYPE_PIPE) | 1970 | if (fh->type != GNUNET_DISK_HANLDE_TYPE_PIPE) |
1955 | continue; | 1971 | continue; |
1956 | /* Read zero bytes to check the status of the pipe */ | 1972 | /* Read zero bytes to check the status of the pipe */ |