2 * Simple Named Pipe Client
3 * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
4 * (C) 2009 Stefan Metzmacher <metze@samba.org>
5 * Published to the public domain
11 #define ECHODATA "Black Dog"
13 int main(int argc
, char *argv
[])
17 char *outbuffer
= malloc(sizeof(ECHODATA
)*2);
18 BOOL small_reads
= FALSE
;
24 } else if (argc
>= 3) {
25 if (strcmp(argv
[2], "large") == 0) {
27 } else if (strcmp(argv
[2], "small") == 0) {
34 h
= CreateFile(argv
[1], GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
35 if (h
== INVALID_HANDLE_VALUE
) {
36 printf("Error opening: %d\n", GetLastError());
40 GetNamedPipeHandleState(h
, &state
, NULL
, NULL
, NULL
, NULL
, 0);
42 if (state
& PIPE_READMODE_MESSAGE
) {
43 printf("message read mode\n");
45 printf("byte read mode\n");
51 DWORD ofs
, size
, nread
;
52 const char *more
= "";
53 printf("small reads\n");
56 size
= sizeof(ECHODATA
)/2;
57 if (ReadFile(h
, outbuffer
+ofs
, size
, &nread
, NULL
)) {
58 if (state
& PIPE_READMODE_MESSAGE
) {
59 printf("Error message mode small read succeeded\n");
62 } else if (GetLastError() == ERROR_MORE_DATA
) {
63 if (!(state
& PIPE_READMODE_MESSAGE
)) {
64 printf("Error byte mode small read returned ERROR_MORE_DATA\n");
69 printf("Error reading: %d\n", GetLastError());
72 printf("Small Read: %d%s\n", nread
, more
);
75 size
= sizeof(ECHODATA
) - ofs
;
76 if (!ReadFile(h
, outbuffer
+ofs
, size
, &nread
, NULL
)) {
77 printf("Error reading: %d\n", GetLastError());
80 printf("Small Read: %d\n", nread
);
83 printf("large read\n");
84 if (!ReadFile(h
, outbuffer
, sizeof(ECHODATA
)*2, &numread
, NULL
)) {
85 printf("Error reading: %d\n", GetLastError());
89 printf("Read: %s %d\n", outbuffer
, numread
);
90 if (state
& PIPE_READMODE_MESSAGE
) {
91 if (numread
!= sizeof(ECHODATA
)) {
92 printf("message mode returned %d bytes should be %s\n",
93 numread
, sizeof(ECHODATA
));
97 if (numread
!= (sizeof(ECHODATA
)*2)) {
98 printf("message mode returned %d bytes should be %s\n",
99 numread
, (sizeof(ECHODATA
)*2));
104 if (!ReadFile(h
, outbuffer
, sizeof(ECHODATA
)*2, &numread
, NULL
)) {
105 printf("Error reading: %d\n", GetLastError());
109 printf("Read: %s %d\n", outbuffer
, numread
);
113 printf("Usage: %s pipename [read]\n", argv
[0]);
114 printf(" Where pipename is something like \\\\servername\\NPECHO\n");
115 printf(" Where read is something 'large' or 'small'\n");