aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2013-01-31 12:32:20 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2013-01-31 12:32:20 +0000
commitb19d787fc3b840821157471bb07f287a68e37709 (patch)
tree0ad5f315f04aad65f8591e42337ddb2eda262303 /src
parent9b4b22d13f5ced89931b0986dc43e1656c539a07 (diff)
downloadgnunet-b19d787fc3b840821157471bb07f287a68e37709.tar.gz
gnunet-b19d787fc3b840821157471bb07f287a68e37709.zip
added support for partial reads from stdin
Diffstat (limited to 'src')
-rw-r--r--src/exit/gnunet-helper-exit-windows.c119
-rw-r--r--src/vpn/gnunet-helper-vpn-windows.c119
2 files changed, 110 insertions, 128 deletions
diff --git a/src/exit/gnunet-helper-exit-windows.c b/src/exit/gnunet-helper-exit-windows.c
index 2b99134cc..65c8bfc86 100644
--- a/src/exit/gnunet-helper-exit-windows.c
+++ b/src/exit/gnunet-helper-exit-windows.c
@@ -205,9 +205,9 @@ struct io_facility
205 DWORD buffer_size; 205 DWORD buffer_size;
206 206
207 /** 207 /**
208 * Amount of data written, is compared to buffer_size. 208 * Amount of data actually written or read by readfile/writefile.
209 */ 209 */
210 DWORD buffer_size_written; 210 DWORD buffer_size_processed;
211}; 211};
212 212
213/** 213/**
@@ -904,10 +904,8 @@ attempt_read_tap (struct io_facility * input_facility,
904 output_facility->facility_state = IOSTATE_READY; 904 output_facility->facility_state = IOSTATE_READY;
905 } 905 }
906 else if (0 < input_facility->buffer_size) 906 else if (0 < input_facility->buffer_size)
907 { /* If we have have read our buffer, wait for our write-partner*/ 907 /* If we have have read our buffer, wait for our write-partner*/
908 input_facility->facility_state = IOSTATE_WAITING; 908 input_facility->facility_state = IOSTATE_WAITING;
909 // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish?
910 }
911 } 909 }
912 else /* operation was either queued or failed*/ 910 else /* operation was either queued or failed*/
913 { 911 {
@@ -1033,31 +1031,33 @@ attempt_read_stdin (struct io_facility * input_facility,
1033 struct io_facility * output_facility) 1031 struct io_facility * output_facility)
1034{ 1032{
1035 struct GNUNET_MessageHeader * hdr; 1033 struct GNUNET_MessageHeader * hdr;
1036 BOOL status; 1034
1037 switch (input_facility->facility_state) 1035 switch (input_facility->facility_state)
1038 { 1036 {
1039 case IOSTATE_READY: 1037 case IOSTATE_READY:
1040 { 1038 {
1039 input_facility->buffer_size = 0;
1040
1041partial_read_iostate_ready:
1041 if (! ResetEvent (input_facility->overlapped.hEvent)) 1042 if (! ResetEvent (input_facility->overlapped.hEvent))
1042 return FALSE; 1043 return FALSE;
1043 input_facility->buffer_size = 0; 1044
1044 status = ReadFile (input_facility->handle,
1045 input_facility->buffer,
1046 sizeof (input_facility->buffer),
1047 &input_facility->buffer_size,
1048 &input_facility->overlapped);
1049
1050 /* Check how the task is handled */ 1045 /* Check how the task is handled */
1051 if (status && (sizeof (struct GNUNET_MessageHeader) < input_facility->buffer_size)) 1046 if (ReadFile (input_facility->handle,
1047 input_facility->buffer + input_facility->buffer_size,
1048 sizeof (input_facility->buffer) - input_facility->buffer_size,
1049 &input_facility->buffer_size_processed,
1050 &input_facility->overlapped))
1052 {/* async event processed immediately*/ 1051 {/* async event processed immediately*/
1053 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; 1052 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer;
1054 1053
1055 /* reset event manually*/ 1054 /* reset event manually*/
1056 if (! SetEvent (input_facility->overlapped.hEvent)) 1055 if (!SetEvent (input_facility->overlapped.hEvent))
1057 return FALSE; 1056 return FALSE;
1058 1057
1059 fprintf (stderr, "DEBUG: stdin read succeeded immediately\n"); 1058 fprintf (stderr, "DEBUG: stdin read succeeded immediately\n");
1060 1059 input_facility->buffer_size += input_facility->buffer_size_processed;
1060
1061 if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER || 1061 if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER ||
1062 ntohs (hdr->size) > sizeof (input_facility->buffer)) 1062 ntohs (hdr->size) > sizeof (input_facility->buffer))
1063 { 1063 {
@@ -1065,44 +1065,36 @@ attempt_read_stdin (struct io_facility * input_facility,
1065 input_facility->facility_state = IOSTATE_READY; 1065 input_facility->facility_state = IOSTATE_READY;
1066 return TRUE; 1066 return TRUE;
1067 } 1067 }
1068 if (ntohs (hdr->size) > input_facility->buffer_size); 1068 /* we got the a part of a packet */
1069 // TODO: add support for partial read 1069 if (ntohs (hdr->size) > input_facility->buffer_size)
1070 1070 goto partial_read_iostate_ready;
1071 /* we successfully read something from the TAP and now need to 1071
1072 /* have we read more than 0 bytes of payload? (sizeread > header)*/
1073 if (input_facility->buffer_size > sizeof (struct GNUNET_MessageHeader) &&
1074 ((IOSTATE_READY == output_facility->facility_state) ||
1075 (IOSTATE_WAITING == output_facility->facility_state)))
1076 {/* we successfully read something from the TAP and now need to
1072 * send it our via STDOUT. Is that possible at the moment? */ 1077 * send it our via STDOUT. Is that possible at the moment? */
1073 if (sizeof (struct GNUNET_MessageHeader) < input_facility->buffer_size)
1074 {
1075 if (IOSTATE_READY == output_facility->facility_state ||
1076 IOSTATE_WAITING == output_facility->facility_state)
1077 {
1078 /* hand over this buffers content and strip gnunet message header */
1079 memcpy (output_facility->buffer,
1080 input_facility->buffer + sizeof (struct GNUNET_MessageHeader),
1081 input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader));
1082 output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader);
1083 output_facility->facility_state = IOSTATE_READY;
1084
1085 }
1086 else if (IOSTATE_QUEUED == output_facility->facility_state)
1087 /* If we have have read our buffer, wait for our write-partner*/
1088 input_facility->facility_state = IOSTATE_WAITING;
1089 // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish?
1090 }
1091 }
1092 else if (status && 0 >= input_facility->buffer_size)
1093 {
1094 if (! SetEvent (input_facility->overlapped.hEvent))
1095 return FALSE;
1096 1078
1097 input_facility->facility_state = IOSTATE_READY; 1079 /* hand over this buffers content and strip gnunet message header */
1098 } 1080 memcpy (output_facility->buffer,
1081 input_facility->buffer + sizeof (struct GNUNET_MessageHeader),
1082 input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader));
1083 output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader);
1084 output_facility->facility_state = IOSTATE_READY;
1085 input_facility->facility_state = IOSTATE_READY;
1086 }
1087 else if (input_facility->buffer_size > sizeof (struct GNUNET_MessageHeader))
1088 /* If we have have read our buffer, wait for our write-partner*/
1089 input_facility->facility_state = IOSTATE_WAITING;
1090 else /* we read nothing */
1091 input_facility->facility_state = IOSTATE_READY;
1092 }
1099 else /* operation was either queued or failed*/ 1093 else /* operation was either queued or failed*/
1100 { 1094 {
1101 int err = GetLastError (); 1095 int err = GetLastError ();
1102 if (ERROR_IO_PENDING == err) 1096 if (ERROR_IO_PENDING == err) /* operation queued */
1103 { /* operation queued */
1104 input_facility->facility_state = IOSTATE_QUEUED; 1097 input_facility->facility_state = IOSTATE_QUEUED;
1105 }
1106 else 1098 else
1107 { /* error occurred, let the rest of the elements finish */ 1099 { /* error occurred, let the rest of the elements finish */
1108 input_facility->path_open = FALSE; 1100 input_facility->path_open = FALSE;
@@ -1121,7 +1113,7 @@ attempt_read_stdin (struct io_facility * input_facility,
1121 // there was an operation going on already, check if that has completed now. 1113 // there was an operation going on already, check if that has completed now.
1122 if (GetOverlappedResult (input_facility->handle, 1114 if (GetOverlappedResult (input_facility->handle,
1123 &input_facility->overlapped, 1115 &input_facility->overlapped,
1124 &input_facility->buffer_size, 1116 &input_facility->buffer_size_processed,
1125 FALSE)) 1117 FALSE))
1126 {/* successful return for a queued operation */ 1118 {/* successful return for a queued operation */
1127 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; 1119 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer;
@@ -1130,6 +1122,7 @@ attempt_read_stdin (struct io_facility * input_facility,
1130 return FALSE; 1122 return FALSE;
1131 1123
1132 fprintf (stderr, "DEBUG: stdin read succeeded delayed\n"); 1124 fprintf (stderr, "DEBUG: stdin read succeeded delayed\n");
1125 input_facility->buffer_size += input_facility->buffer_size_processed;
1133 1126
1134 if ((ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || 1127 if ((ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) ||
1135 (ntohs (hdr->size) > sizeof (input_facility->buffer))) 1128 (ntohs (hdr->size) > sizeof (input_facility->buffer)))
@@ -1138,14 +1131,15 @@ attempt_read_stdin (struct io_facility * input_facility,
1138 input_facility->facility_state = IOSTATE_READY; 1131 input_facility->facility_state = IOSTATE_READY;
1139 return TRUE; 1132 return TRUE;
1140 } 1133 }
1134 /* we got the a part of a packet */
1141 if (ntohs (hdr->size) > input_facility->buffer_size ); 1135 if (ntohs (hdr->size) > input_facility->buffer_size );
1142 // TODO: add support for partial read 1136 goto partial_read_iostate_ready;
1143 1137
1144 /* we successfully read something from the TAP and now need to 1138 /* we successfully read something from the TAP and now need to
1145 * send it our via STDOUT. Is that possible at the moment? */ 1139 * send it our via STDOUT. Is that possible at the moment? */
1146 if ((IOSTATE_READY == output_facility->facility_state || 1140 if ((IOSTATE_READY == output_facility->facility_state ||
1147 IOSTATE_WAITING == output_facility->facility_state) 1141 IOSTATE_WAITING == output_facility->facility_state)
1148 && sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size) 1142 && input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
1149 { /* hand over this buffers content and strip gnunet message header */ 1143 { /* hand over this buffers content and strip gnunet message header */
1150 memcpy (output_facility->buffer, 1144 memcpy (output_facility->buffer,
1151 input_facility->buffer + sizeof(struct GNUNET_MessageHeader), 1145 input_facility->buffer + sizeof(struct GNUNET_MessageHeader),
@@ -1154,12 +1148,9 @@ attempt_read_stdin (struct io_facility * input_facility,
1154 output_facility->facility_state = IOSTATE_READY; 1148 output_facility->facility_state = IOSTATE_READY;
1155 input_facility->facility_state = IOSTATE_READY; 1149 input_facility->facility_state = IOSTATE_READY;
1156 } 1150 }
1157 else if (sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size) 1151 else if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
1158 { /* If we have have read our buffer, wait for our write-partner*/ 1152 input_facility->facility_state = IOSTATE_WAITING;
1159 input_facility->facility_state = IOSTATE_WAITING; 1153 else
1160 // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish?
1161 }
1162 else if (sizeof(struct GNUNET_MessageHeader) >= input_facility->buffer_size)
1163 input_facility->facility_state = IOSTATE_READY; 1154 input_facility->facility_state = IOSTATE_READY;
1164 } 1155 }
1165 else 1156 else
@@ -1212,16 +1203,16 @@ attempt_write (struct io_facility * output_facility,
1212 if (! ResetEvent (output_facility->overlapped.hEvent)) 1203 if (! ResetEvent (output_facility->overlapped.hEvent))
1213 return FALSE; 1204 return FALSE;
1214 1205
1215 output_facility->buffer_size_written = 0; 1206 output_facility->buffer_size_processed = 0;
1216 status = WriteFile (output_facility->handle, 1207 status = WriteFile (output_facility->handle,
1217 output_facility->buffer, 1208 output_facility->buffer,
1218 output_facility->buffer_size, 1209 output_facility->buffer_size,
1219 &output_facility->buffer_size_written, 1210 &output_facility->buffer_size_processed,
1220 &output_facility->overlapped); 1211 &output_facility->overlapped);
1221 1212
1222 /* Check how the task was handled */ 1213 /* Check how the task was handled */
1223 if (status && 1214 if (status &&
1224 output_facility->buffer_size_written == output_facility->buffer_size) 1215 output_facility->buffer_size_processed == output_facility->buffer_size)
1225 {/* async event processed immediately*/ 1216 {/* async event processed immediately*/
1226 1217
1227 fprintf (stderr, "DEBUG: write succeeded immediately\n"); 1218 fprintf (stderr, "DEBUG: write succeeded immediately\n");
@@ -1233,7 +1224,7 @@ attempt_write (struct io_facility * output_facility,
1233 /* we are now waiting for our buffer to be filled*/ 1224 /* we are now waiting for our buffer to be filled*/
1234 output_facility->facility_state = IOSTATE_WAITING; 1225 output_facility->facility_state = IOSTATE_WAITING;
1235 output_facility->buffer_size = 0; 1226 output_facility->buffer_size = 0;
1236 output_facility->buffer_size_written = 0; 1227 output_facility->buffer_size_processed = 0;
1237 1228
1238 /* we successfully wrote something and now need to reset our reader */ 1229 /* we successfully wrote something and now need to reset our reader */
1239 if (IOSTATE_WAITING == input_facility->facility_state) 1230 if (IOSTATE_WAITING == input_facility->facility_state)
@@ -1260,10 +1251,10 @@ attempt_write (struct io_facility * output_facility,
1260 // there was an operation going on already, check if that has completed now. 1251 // there was an operation going on already, check if that has completed now.
1261 status = GetOverlappedResult (output_facility->handle, 1252 status = GetOverlappedResult (output_facility->handle,
1262 &output_facility->overlapped, 1253 &output_facility->overlapped,
1263 &output_facility->buffer_size_written, 1254 &output_facility->buffer_size_processed,
1264 FALSE); 1255 FALSE);
1265 if (status && 1256 if (status &&
1266 output_facility->buffer_size_written == output_facility->buffer_size) 1257 output_facility->buffer_size_processed == output_facility->buffer_size)
1267 {/* successful return for a queued operation */ 1258 {/* successful return for a queued operation */
1268 if (! ResetEvent (output_facility->overlapped.hEvent)) 1259 if (! ResetEvent (output_facility->overlapped.hEvent))
1269 return FALSE; 1260 return FALSE;
@@ -1273,7 +1264,7 @@ attempt_write (struct io_facility * output_facility,
1273 /* we are now waiting for our buffer to be filled*/ 1264 /* we are now waiting for our buffer to be filled*/
1274 output_facility->facility_state = IOSTATE_WAITING; 1265 output_facility->facility_state = IOSTATE_WAITING;
1275 output_facility->buffer_size = 0; 1266 output_facility->buffer_size = 0;
1276 output_facility->buffer_size_written = 0; 1267 output_facility->buffer_size_processed = 0;
1277 1268
1278 /* we successfully wrote something and now need to reset our reader */ 1269 /* we successfully wrote something and now need to reset our reader */
1279 if (IOSTATE_WAITING == input_facility->facility_state) 1270 if (IOSTATE_WAITING == input_facility->facility_state)
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c
index dbf5663e4..bd364ec7e 100644
--- a/src/vpn/gnunet-helper-vpn-windows.c
+++ b/src/vpn/gnunet-helper-vpn-windows.c
@@ -218,9 +218,9 @@ struct io_facility
218 DWORD buffer_size; 218 DWORD buffer_size;
219 219
220 /** 220 /**
221 * Amount of data written, is compared to buffer_size. 221 * Amount of data actually written or read by readfile/writefile.
222 */ 222 */
223 DWORD buffer_size_written; 223 DWORD buffer_size_processed;
224}; 224};
225 225
226/** 226/**
@@ -917,10 +917,8 @@ attempt_read_tap (struct io_facility * input_facility,
917 output_facility->facility_state = IOSTATE_READY; 917 output_facility->facility_state = IOSTATE_READY;
918 } 918 }
919 else if (0 < input_facility->buffer_size) 919 else if (0 < input_facility->buffer_size)
920 { /* If we have have read our buffer, wait for our write-partner*/ 920 /* If we have have read our buffer, wait for our write-partner*/
921 input_facility->facility_state = IOSTATE_WAITING; 921 input_facility->facility_state = IOSTATE_WAITING;
922 // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish?
923 }
924 } 922 }
925 else /* operation was either queued or failed*/ 923 else /* operation was either queued or failed*/
926 { 924 {
@@ -1046,31 +1044,33 @@ attempt_read_stdin (struct io_facility * input_facility,
1046 struct io_facility * output_facility) 1044 struct io_facility * output_facility)
1047{ 1045{
1048 struct GNUNET_MessageHeader * hdr; 1046 struct GNUNET_MessageHeader * hdr;
1049 BOOL status; 1047
1050 switch (input_facility->facility_state) 1048 switch (input_facility->facility_state)
1051 { 1049 {
1052 case IOSTATE_READY: 1050 case IOSTATE_READY:
1053 { 1051 {
1052 input_facility->buffer_size = 0;
1053
1054partial_read_iostate_ready:
1054 if (! ResetEvent (input_facility->overlapped.hEvent)) 1055 if (! ResetEvent (input_facility->overlapped.hEvent))
1055 return FALSE; 1056 return FALSE;
1056 input_facility->buffer_size = 0; 1057
1057 status = ReadFile (input_facility->handle,
1058 input_facility->buffer,
1059 sizeof (input_facility->buffer),
1060 &input_facility->buffer_size,
1061 &input_facility->overlapped);
1062
1063 /* Check how the task is handled */ 1058 /* Check how the task is handled */
1064 if (status && (sizeof (struct GNUNET_MessageHeader) < input_facility->buffer_size)) 1059 if (ReadFile (input_facility->handle,
1060 input_facility->buffer + input_facility->buffer_size,
1061 sizeof (input_facility->buffer) - input_facility->buffer_size,
1062 &input_facility->buffer_size_processed,
1063 &input_facility->overlapped))
1065 {/* async event processed immediately*/ 1064 {/* async event processed immediately*/
1066 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; 1065 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer;
1067 1066
1068 /* reset event manually*/ 1067 /* reset event manually*/
1069 if (! SetEvent (input_facility->overlapped.hEvent)) 1068 if (!SetEvent (input_facility->overlapped.hEvent))
1070 return FALSE; 1069 return FALSE;
1071 1070
1072 fprintf (stderr, "DEBUG: stdin read succeeded immediately\n"); 1071 fprintf (stderr, "DEBUG: stdin read succeeded immediately\n");
1073 1072 input_facility->buffer_size += input_facility->buffer_size_processed;
1073
1074 if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER || 1074 if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER ||
1075 ntohs (hdr->size) > sizeof (input_facility->buffer)) 1075 ntohs (hdr->size) > sizeof (input_facility->buffer))
1076 { 1076 {
@@ -1078,44 +1078,36 @@ attempt_read_stdin (struct io_facility * input_facility,
1078 input_facility->facility_state = IOSTATE_READY; 1078 input_facility->facility_state = IOSTATE_READY;
1079 return TRUE; 1079 return TRUE;
1080 } 1080 }
1081 if (ntohs (hdr->size) > input_facility->buffer_size); 1081 /* we got the a part of a packet */
1082 // TODO: add support for partial read 1082 if (ntohs (hdr->size) > input_facility->buffer_size)
1083 1083 goto partial_read_iostate_ready;
1084 /* we successfully read something from the TAP and now need to 1084
1085 /* have we read more than 0 bytes of payload? (sizeread > header)*/
1086 if (input_facility->buffer_size > sizeof (struct GNUNET_MessageHeader) &&
1087 ((IOSTATE_READY == output_facility->facility_state) ||
1088 (IOSTATE_WAITING == output_facility->facility_state)))
1089 {/* we successfully read something from the TAP and now need to
1085 * send it our via STDOUT. Is that possible at the moment? */ 1090 * send it our via STDOUT. Is that possible at the moment? */
1086 if (sizeof (struct GNUNET_MessageHeader) < input_facility->buffer_size)
1087 {
1088 if (IOSTATE_READY == output_facility->facility_state ||
1089 IOSTATE_WAITING == output_facility->facility_state)
1090 {
1091 /* hand over this buffers content and strip gnunet message header */
1092 memcpy (output_facility->buffer,
1093 input_facility->buffer + sizeof (struct GNUNET_MessageHeader),
1094 input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader));
1095 output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader);
1096 output_facility->facility_state = IOSTATE_READY;
1097
1098 }
1099 else if (IOSTATE_QUEUED == output_facility->facility_state)
1100 /* If we have have read our buffer, wait for our write-partner*/
1101 input_facility->facility_state = IOSTATE_WAITING;
1102 // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish?
1103 }
1104 }
1105 else if (status && 0 >= input_facility->buffer_size)
1106 {
1107 if (! SetEvent (input_facility->overlapped.hEvent))
1108 return FALSE;
1109 1091
1110 input_facility->facility_state = IOSTATE_READY; 1092 /* hand over this buffers content and strip gnunet message header */
1111 } 1093 memcpy (output_facility->buffer,
1094 input_facility->buffer + sizeof (struct GNUNET_MessageHeader),
1095 input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader));
1096 output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader);
1097 output_facility->facility_state = IOSTATE_READY;
1098 input_facility->facility_state = IOSTATE_READY;
1099 }
1100 else if (input_facility->buffer_size > sizeof (struct GNUNET_MessageHeader))
1101 /* If we have have read our buffer, wait for our write-partner*/
1102 input_facility->facility_state = IOSTATE_WAITING;
1103 else /* we read nothing */
1104 input_facility->facility_state = IOSTATE_READY;
1105 }
1112 else /* operation was either queued or failed*/ 1106 else /* operation was either queued or failed*/
1113 { 1107 {
1114 int err = GetLastError (); 1108 int err = GetLastError ();
1115 if (ERROR_IO_PENDING == err) 1109 if (ERROR_IO_PENDING == err) /* operation queued */
1116 { /* operation queued */
1117 input_facility->facility_state = IOSTATE_QUEUED; 1110 input_facility->facility_state = IOSTATE_QUEUED;
1118 }
1119 else 1111 else
1120 { /* error occurred, let the rest of the elements finish */ 1112 { /* error occurred, let the rest of the elements finish */
1121 input_facility->path_open = FALSE; 1113 input_facility->path_open = FALSE;
@@ -1134,7 +1126,7 @@ attempt_read_stdin (struct io_facility * input_facility,
1134 // there was an operation going on already, check if that has completed now. 1126 // there was an operation going on already, check if that has completed now.
1135 if (GetOverlappedResult (input_facility->handle, 1127 if (GetOverlappedResult (input_facility->handle,
1136 &input_facility->overlapped, 1128 &input_facility->overlapped,
1137 &input_facility->buffer_size, 1129 &input_facility->buffer_size_processed,
1138 FALSE)) 1130 FALSE))
1139 {/* successful return for a queued operation */ 1131 {/* successful return for a queued operation */
1140 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; 1132 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer;
@@ -1143,6 +1135,7 @@ attempt_read_stdin (struct io_facility * input_facility,
1143 return FALSE; 1135 return FALSE;
1144 1136
1145 fprintf (stderr, "DEBUG: stdin read succeeded delayed\n"); 1137 fprintf (stderr, "DEBUG: stdin read succeeded delayed\n");
1138 input_facility->buffer_size += input_facility->buffer_size_processed;
1146 1139
1147 if ((ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || 1140 if ((ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) ||
1148 (ntohs (hdr->size) > sizeof (input_facility->buffer))) 1141 (ntohs (hdr->size) > sizeof (input_facility->buffer)))
@@ -1151,14 +1144,15 @@ attempt_read_stdin (struct io_facility * input_facility,
1151 input_facility->facility_state = IOSTATE_READY; 1144 input_facility->facility_state = IOSTATE_READY;
1152 return TRUE; 1145 return TRUE;
1153 } 1146 }
1147 /* we got the a part of a packet */
1154 if (ntohs (hdr->size) > input_facility->buffer_size ); 1148 if (ntohs (hdr->size) > input_facility->buffer_size );
1155 // TODO: add support for partial read 1149 goto partial_read_iostate_ready;
1156 1150
1157 /* we successfully read something from the TAP and now need to 1151 /* we successfully read something from the TAP and now need to
1158 * send it our via STDOUT. Is that possible at the moment? */ 1152 * send it our via STDOUT. Is that possible at the moment? */
1159 if ((IOSTATE_READY == output_facility->facility_state || 1153 if ((IOSTATE_READY == output_facility->facility_state ||
1160 IOSTATE_WAITING == output_facility->facility_state) 1154 IOSTATE_WAITING == output_facility->facility_state)
1161 && sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size) 1155 && input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
1162 { /* hand over this buffers content and strip gnunet message header */ 1156 { /* hand over this buffers content and strip gnunet message header */
1163 memcpy (output_facility->buffer, 1157 memcpy (output_facility->buffer,
1164 input_facility->buffer + sizeof(struct GNUNET_MessageHeader), 1158 input_facility->buffer + sizeof(struct GNUNET_MessageHeader),
@@ -1167,12 +1161,9 @@ attempt_read_stdin (struct io_facility * input_facility,
1167 output_facility->facility_state = IOSTATE_READY; 1161 output_facility->facility_state = IOSTATE_READY;
1168 input_facility->facility_state = IOSTATE_READY; 1162 input_facility->facility_state = IOSTATE_READY;
1169 } 1163 }
1170 else if (sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size) 1164 else if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
1171 { /* If we have have read our buffer, wait for our write-partner*/ 1165 input_facility->facility_state = IOSTATE_WAITING;
1172 input_facility->facility_state = IOSTATE_WAITING; 1166 else
1173 // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish?
1174 }
1175 else if (sizeof(struct GNUNET_MessageHeader) >= input_facility->buffer_size)
1176 input_facility->facility_state = IOSTATE_READY; 1167 input_facility->facility_state = IOSTATE_READY;
1177 } 1168 }
1178 else 1169 else
@@ -1225,16 +1216,16 @@ attempt_write (struct io_facility * output_facility,
1225 if (! ResetEvent (output_facility->overlapped.hEvent)) 1216 if (! ResetEvent (output_facility->overlapped.hEvent))
1226 return FALSE; 1217 return FALSE;
1227 1218
1228 output_facility->buffer_size_written = 0; 1219 output_facility->buffer_size_processed = 0;
1229 status = WriteFile (output_facility->handle, 1220 status = WriteFile (output_facility->handle,
1230 output_facility->buffer, 1221 output_facility->buffer,
1231 output_facility->buffer_size, 1222 output_facility->buffer_size,
1232 &output_facility->buffer_size_written, 1223 &output_facility->buffer_size_processed,
1233 &output_facility->overlapped); 1224 &output_facility->overlapped);
1234 1225
1235 /* Check how the task was handled */ 1226 /* Check how the task was handled */
1236 if (status && 1227 if (status &&
1237 output_facility->buffer_size_written == output_facility->buffer_size) 1228 output_facility->buffer_size_processed == output_facility->buffer_size)
1238 {/* async event processed immediately*/ 1229 {/* async event processed immediately*/
1239 1230
1240 fprintf (stderr, "DEBUG: write succeeded immediately\n"); 1231 fprintf (stderr, "DEBUG: write succeeded immediately\n");
@@ -1246,7 +1237,7 @@ attempt_write (struct io_facility * output_facility,
1246 /* we are now waiting for our buffer to be filled*/ 1237 /* we are now waiting for our buffer to be filled*/
1247 output_facility->facility_state = IOSTATE_WAITING; 1238 output_facility->facility_state = IOSTATE_WAITING;
1248 output_facility->buffer_size = 0; 1239 output_facility->buffer_size = 0;
1249 output_facility->buffer_size_written = 0; 1240 output_facility->buffer_size_processed = 0;
1250 1241
1251 /* we successfully wrote something and now need to reset our reader */ 1242 /* we successfully wrote something and now need to reset our reader */
1252 if (IOSTATE_WAITING == input_facility->facility_state) 1243 if (IOSTATE_WAITING == input_facility->facility_state)
@@ -1273,10 +1264,10 @@ attempt_write (struct io_facility * output_facility,
1273 // there was an operation going on already, check if that has completed now. 1264 // there was an operation going on already, check if that has completed now.
1274 status = GetOverlappedResult (output_facility->handle, 1265 status = GetOverlappedResult (output_facility->handle,
1275 &output_facility->overlapped, 1266 &output_facility->overlapped,
1276 &output_facility->buffer_size_written, 1267 &output_facility->buffer_size_processed,
1277 FALSE); 1268 FALSE);
1278 if (status && 1269 if (status &&
1279 output_facility->buffer_size_written == output_facility->buffer_size) 1270 output_facility->buffer_size_processed == output_facility->buffer_size)
1280 {/* successful return for a queued operation */ 1271 {/* successful return for a queued operation */
1281 if (! ResetEvent (output_facility->overlapped.hEvent)) 1272 if (! ResetEvent (output_facility->overlapped.hEvent))
1282 return FALSE; 1273 return FALSE;
@@ -1286,7 +1277,7 @@ attempt_write (struct io_facility * output_facility,
1286 /* we are now waiting for our buffer to be filled*/ 1277 /* we are now waiting for our buffer to be filled*/
1287 output_facility->facility_state = IOSTATE_WAITING; 1278 output_facility->facility_state = IOSTATE_WAITING;
1288 output_facility->buffer_size = 0; 1279 output_facility->buffer_size = 0;
1289 output_facility->buffer_size_written = 0; 1280 output_facility->buffer_size_processed = 0;
1290 1281
1291 /* we successfully wrote something and now need to reset our reader */ 1282 /* we successfully wrote something and now need to reset our reader */
1292 if (IOSTATE_WAITING == input_facility->facility_state) 1283 if (IOSTATE_WAITING == input_facility->facility_state)