diff options
author | Stefan Metzmacher <metze@samba.org> | 2009-02-09 13:31:03 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2009-02-09 13:32:11 +0100 |
commit | 3ce895181be9f0a91c17c1c5261a92159f154a86 (patch) | |
tree | 28d6c3bd205f03f5d73aceb253be71630f5d0eb0 | |
parent | d78fd1954714cbd033247668bad80a92bbd048e1 (diff) | |
download | samba-3ce895181be9f0a91c17c1c5261a92159f154a86.tar.gz samba-3ce895181be9f0a91c17c1c5261a92159f154a86.tar.bz2 samba-3ce895181be9f0a91c17c1c5261a92159f154a86.zip |
testprogs/win32: add an option to trigger small reads in npecho_client2.c
metze
-rwxr-xr-x | testprogs/win32/npecho/npecho_client2.c | 83 |
1 files changed, 76 insertions, 7 deletions
diff --git a/testprogs/win32/npecho/npecho_client2.c b/testprogs/win32/npecho/npecho_client2.c index 892574beb0..ebf4f9ad17 100755 --- a/testprogs/win32/npecho/npecho_client2.c +++ b/testprogs/win32/npecho/npecho_client2.c @@ -15,11 +15,20 @@ int main(int argc, char *argv[]) HANDLE h; DWORD numread = 0; char *outbuffer = malloc(sizeof(ECHODATA)*2); + BOOL small_reads = FALSE; + DWORD state = 0; + DWORD flags = 0; if (argc == 1) { - printf("Usage: %s pipename\n", argv[0]); - printf(" Where pipename is something like \\\\servername\\NPECHO\n"); - return -1; + goto usage; + } else if (argc >= 3) { + if (strcmp(argv[2], "large") == 0) { + small_reads = FALSE; + } else if (strcmp(argv[2], "small") == 0) { + small_reads = TRUE; + } else { + goto usage; + } } h = CreateFile(argv[1], GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); @@ -28,14 +37,69 @@ int main(int argc, char *argv[]) return -1; } - Sleep(5000); + GetNamedPipeHandleState(h, &state, NULL, NULL, NULL, NULL, 0); - if (!ReadFile(h, outbuffer, sizeof(ECHODATA)*2, &numread, NULL)) { - printf("Error reading: %d\n", GetLastError()); - return -1; + if (state & PIPE_READMODE_MESSAGE) { + printf("message read mode\n"); + } else { + printf("byte read mode\n"); } + Sleep(5000); + + if (small_reads) { + DWORD ofs, size, nread; + const char *more = ""; + printf("small reads\n"); + numread = 0; + ofs = 0; + size = sizeof(ECHODATA)/2; + if (ReadFile(h, outbuffer+ofs, size, &nread, NULL)) { + if (state & PIPE_READMODE_MESSAGE) { + printf("Error message mode small read succeeded\n"); + return -1; + } + } else if (GetLastError() == ERROR_MORE_DATA) { + if (!(state & PIPE_READMODE_MESSAGE)) { + printf("Error byte mode small read returned ERROR_MORE_DATA\n"); + return -1; + } + more = " more data"; + } else { + printf("Error reading: %d\n", GetLastError()); + return -1; + } + printf("Small Read: %d%s\n", nread, more); + numread += nread; + ofs = size; + size = sizeof(ECHODATA) - ofs; + if (!ReadFile(h, outbuffer+ofs, size, &nread, NULL)) { + printf("Error reading: %d\n", GetLastError()); + return -1; + } + printf("Small Read: %d\n", nread); + numread += nread; + } else { + printf("large read\n"); + if (!ReadFile(h, outbuffer, sizeof(ECHODATA)*2, &numread, NULL)) { + printf("Error reading: %d\n", GetLastError()); + return -1; + } + } printf("Read: %s %d\n", outbuffer, numread); + if (state & PIPE_READMODE_MESSAGE) { + if (numread != sizeof(ECHODATA)) { + printf("message mode returned %d bytes should be %s\n", + numread, sizeof(ECHODATA)); + return -1; + } + } else { + if (numread != (sizeof(ECHODATA)*2)) { + printf("message mode returned %d bytes should be %s\n", + numread, (sizeof(ECHODATA)*2)); + return -1; + } + } if (!ReadFile(h, outbuffer, sizeof(ECHODATA)*2, &numread, NULL)) { printf("Error reading: %d\n", GetLastError()); @@ -45,4 +109,9 @@ int main(int argc, char *argv[]) printf("Read: %s %d\n", outbuffer, numread); return 0; +usage: + printf("Usage: %s pipename [read]\n", argv[0]); + printf(" Where pipename is something like \\\\servername\\NPECHO\n"); + printf(" Where read is something 'large' or 'small'\n"); + return -1; } |