diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-01-08 14:08:32 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-01-08 14:08:32 +0000 |
commit | 5946ebefa5627be62f4f4ad78ad8917c3ce69e11 (patch) | |
tree | 4609381abd1c13918a5d83dbcca86fa9ebf8ff0d /src/vpn | |
parent | e274742513b2b97d6fb9e12460438c1a7f3fc18a (diff) | |
download | gnunet-5946ebefa5627be62f4f4ad78ad8917c3ce69e11.tar.gz gnunet-5946ebefa5627be62f4f4ad78ad8917c3ce69e11.zip |
fixed a wrong conditional
more research on the conin/stdin+overlapping issue.
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/gnunet-helper-vpn-windows.c | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c index 98e82dad9..516ba5d0e 100644 --- a/src/vpn/gnunet-helper-vpn-windows.c +++ b/src/vpn/gnunet-helper-vpn-windows.c | |||
@@ -700,9 +700,42 @@ tun_up (HANDLE handle) | |||
700 | } | 700 | } |
701 | 701 | ||
702 | static boolean | 702 | static boolean |
703 | attempt_std_in ( struct overlapped_facility * std_in, | 703 | attempt_std_in (HANDLE stdin_handle, |
704 | struct overlapped_facility * tap_write) | 704 | struct overlapped_facility * std_in, |
705 | struct overlapped_facility * tap_write) | ||
705 | { | 706 | { |
707 | |||
708 | // We could use PeekConsoleInput() or WaitForSingleObject() | ||
709 | // however, the interwebs states that WaitForSingleObject with filehandles | ||
710 | // might misbehave on some windows (unspecified which ones!). | ||
711 | // unfortunately, peekconsoleinput () just waits for KEYPRESS-event, which would never happen on a pipe or a file | ||
712 | |||
713 | // See: | ||
714 | // http://www.cplusplus.com/forum/windows/28837/ | ||
715 | // http://stackoverflow.com/questions/4551644/using-overlapped-io-for-console-input | ||
716 | // http://cygwin.com/ml/cygwin/2012-05/msg00322.html | ||
717 | |||
718 | // possible soltion? | ||
719 | // http://stackoverflow.com/questions/3661106/overlapped-readfileex-on-child-process-redirected-stdout-never-fires | ||
720 | |||
721 | // we may read from STDIN, and no job was active | ||
722 | if (IOSTATE_READY == std_in->iostate){ | ||
723 | |||
724 | } | ||
725 | // we must complete a previous read from stdin, before doing more work | ||
726 | else if (IOSTATE_QUEUED == std_in->iostate ){ | ||
727 | // there is some data to be read from STDIN! | ||
728 | /* if (PeekConsoleInput(stdin_handle, | ||
729 | &std_in->buffer[MAX_SIZE], | ||
730 | MAX_SIZE, | ||
731 | &std_in->buffer_size)){ | ||
732 | |||
733 | |||
734 | |||
735 | }*/ | ||
736 | // else { // nothing to do, try again next time } | ||
737 | } | ||
738 | |||
706 | return TRUE; | 739 | return TRUE; |
707 | } | 740 | } |
708 | 741 | ||
@@ -745,7 +778,7 @@ attempt_tap_read (HANDLE tap_handle, | |||
745 | else if (0 < tap_read->buffer_size) | 778 | else if (0 < tap_read->buffer_size) |
746 | { /* If we have have read our buffer, wait for our write-partner*/ | 779 | { /* If we have have read our buffer, wait for our write-partner*/ |
747 | tap_read->iostate = IOSTATE_WAITING; | 780 | tap_read->iostate = IOSTATE_WAITING; |
748 | // TODO: shall we attempt to fill our bufferm or should we wait for our write-partner to finish? | 781 | // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish? |
749 | } | 782 | } |
750 | } | 783 | } |
751 | else /* operation was either queued or failed*/ | 784 | else /* operation was either queued or failed*/ |
@@ -789,7 +822,7 @@ attempt_tap_read (HANDLE tap_handle, | |||
789 | else if (0 < tap_read->buffer_size) | 822 | else if (0 < tap_read->buffer_size) |
790 | { /* If we have have read our buffer, wait for our write-partner*/ | 823 | { /* If we have have read our buffer, wait for our write-partner*/ |
791 | tap_read->iostate = IOSTATE_WAITING; | 824 | tap_read->iostate = IOSTATE_WAITING; |
792 | // TODO: shall we attempt to fill our bufferm or should we wait for our write-partner to finish? | 825 | // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish? |
793 | } | 826 | } |
794 | } | 827 | } |
795 | else | 828 | else |
@@ -814,8 +847,9 @@ attempt_tap_write (HANDLE tap_handle, | |||
814 | } | 847 | } |
815 | 848 | ||
816 | static boolean | 849 | static boolean |
817 | attempt_std_out ( struct overlapped_facility * std_out, | 850 | attempt_std_out (HANDLE stdout_handle, |
818 | struct overlapped_facility * tap_read) | 851 | struct overlapped_facility * std_out, |
852 | struct overlapped_facility * tap_read) | ||
819 | { | 853 | { |
820 | return TRUE; | 854 | return TRUE; |
821 | } | 855 | } |
@@ -861,6 +895,10 @@ run (HANDLE tap_handle) | |||
861 | struct overlapped_facility std_in; | 895 | struct overlapped_facility std_in; |
862 | /* IO-Facility for writing to stdout */ | 896 | /* IO-Facility for writing to stdout */ |
863 | struct overlapped_facility std_out; | 897 | struct overlapped_facility std_out; |
898 | |||
899 | /* Handles for STDIN and STDOUT */ | ||
900 | HANDLE stdin_handle = INVALID_HANDLE_VALUE; | ||
901 | HANDLE stdout_handle = INVALID_HANDLE_VALUE; | ||
864 | 902 | ||
865 | /* tun up: */ | 903 | /* tun up: */ |
866 | /* we do this HERE and not beforehand (in init_tun()), in contrast to openvpn | 904 | /* we do this HERE and not beforehand (in init_tun()), in contrast to openvpn |
@@ -873,13 +911,22 @@ run (HANDLE tap_handle) | |||
873 | goto teardown; | 911 | goto teardown; |
874 | 912 | ||
875 | /* Initialize our overlapped IO structures*/ | 913 | /* Initialize our overlapped IO structures*/ |
876 | if (initialize_overlapped_facility (&tap_read, TRUE, FALSE) | 914 | if (!(initialize_overlapped_facility (&tap_read, TRUE, FALSE) |
877 | && initialize_overlapped_facility (&tap_write, FALSE, TRUE) | 915 | && initialize_overlapped_facility (&tap_write, FALSE, TRUE) |
878 | && initialize_overlapped_facility (&std_in, TRUE, FALSE) | 916 | && initialize_overlapped_facility (&std_in, TRUE, FALSE) |
879 | && initialize_overlapped_facility (&std_out, FALSE, TRUE)) | 917 | && initialize_overlapped_facility (&std_out, FALSE, TRUE))) |
880 | goto teardown; | 918 | goto teardown; |
881 | 919 | ||
920 | stdin_handle = GetStdHandle ( STD_INPUT_HANDLE ); | ||
921 | |||
922 | if (stdin_handle == INVALID_HANDLE_VALUE) | ||
923 | fprintf (stderr, "CreateFile failed for stdin\n"); | ||
882 | 924 | ||
925 | stdin_handle = GetStdHandle ( STD_OUTPUT_HANDLE ); | ||
926 | |||
927 | if (stdin_handle == INVALID_HANDLE_VALUE) | ||
928 | fprintf (stderr, "CreateFile failed for stdout\n"); | ||
929 | |||
883 | //openvpn | 930 | //openvpn |
884 | // Set Device to Subnet-Mode? | 931 | // Set Device to Subnet-Mode? |
885 | // do we really need tun.c:2925 ? | 932 | // do we really need tun.c:2925 ? |
@@ -900,7 +947,7 @@ run (HANDLE tap_handle) | |||
900 | /* perform READ from stdin if possible */ | 947 | /* perform READ from stdin if possible */ |
901 | if ((std_in.path_open && tap_write.path_open) | 948 | if ((std_in.path_open && tap_write.path_open) |
902 | || IOSTATE_QUEUED == std_in.iostate) | 949 | || IOSTATE_QUEUED == std_in.iostate) |
903 | if (!attempt_std_in (&std_in, &tap_write)) | 950 | if (!attempt_std_in (stdin_handle, &std_in, &tap_write)) |
904 | break; | 951 | break; |
905 | 952 | ||
906 | /* perform READ from tap if possible */ | 953 | /* perform READ from tap if possible */ |
@@ -916,7 +963,7 @@ run (HANDLE tap_handle) | |||
916 | 963 | ||
917 | /* perform WRITE to STDOUT if possible */ | 964 | /* perform WRITE to STDOUT if possible */ |
918 | if ( IOSTATE_READY == std_out.iostate && std_out.path_open) | 965 | if ( IOSTATE_READY == std_out.iostate && std_out.path_open) |
919 | if (!attempt_std_out (&std_out, &tap_read)) | 966 | if (!attempt_std_out (stdout_handle, &std_out, &tap_read)) |
920 | break; | 967 | break; |
921 | 968 | ||
922 | // check if any path is blocked | 969 | // check if any path is blocked |