Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SONPClient.cpp.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <Windows.h>
- #include <cassert>
- #define NAMED_PIPE L"\\\\.\\pipe\\stackoverflow"
- int main()
- {
- HANDLE hPipe = CreateFile(
- NAMED_PIPE,
- GENERIC_READ | GENERIC_WRITE,
- 0,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
- assert(hPipe != INVALID_HANDLE_VALUE);
- unsigned total_read = 0;
- const unsigned buffer_size = 8092; //2x the pipe buffer size. half of this buffer will be unused
- char * buf = new char[buffer_size];
- DWORD bytes_read;
- while (ReadFile(hPipe, buf, buffer_size, &bytes_read, NULL))
- {
- //I'm actually getting reads of 8092 bytes despite the server pipe buffer size being 4096.
- //assert(bytes_read <= 4096);
- total_read += bytes_read;
- for (unsigned ix = 0; ix < bytes_read; ix++)
- {
- assert(buf[ix] == 'a'); //just to prove something real comes over the pipes
- }
- memset(buf, 0, buffer_size);
- }
- assert(total_read == 80 * 1024); //all data is received.
- CloseHandle(hPipe);
- delete[] buf;
- return 0;
- }
Add Comment
Please, Sign In to add comment