Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SONPServer.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <Windows.h>
- #include <cassert>
- #define NAMED_PIPE L"\\\\.\\pipe\\stackoverflow"
- #define READ_BUFFER_SIZE 4096
- #define WRITE_BUFFER_SIZE 4096
- int main()
- {
- HANDLE pipe_handle = CreateNamedPipeW(
- NAMED_PIPE,
- PIPE_ACCESS_DUPLEX,
- PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
- PIPE_UNLIMITED_INSTANCES,
- WRITE_BUFFER_SIZE,
- READ_BUFFER_SIZE,
- NMPWAIT_USE_DEFAULT_WAIT,
- NULL);
- BOOL connected = ConnectNamedPipe(pipe_handle, NULL);
- assert(connected);
- const unsigned buffer_size = 80 * 1024;
- char * buf = new char[buffer_size];
- assert(buf);
- memset(buf, 'a', buffer_size);
- DWORD bytes_written;
- //write 80 KB
- BOOL successful_write = WriteFile(pipe_handle, buf, buffer_size, &bytes_written, NULL);
- assert(successful_write);
- assert(bytes_written == buffer_size); //80 KB were written with one WriteFile call
- //to force all the data over the pipe before we close the handle
- FlushFileBuffers(pipe_handle);
- DisconnectNamedPipe(pipe_handle);
- CloseHandle(pipe_handle);
- delete[] buf;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment