-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipe.cpp
61 lines (51 loc) · 1.56 KB
/
pipe.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "pipe.hpp"
#include <tchar.h>
namespace w32
{
namespace detail
{
static const DWORD
DEF_PIPE_BUFSIZE = 1024 * 4, // output buffer size
DEF_PIPE_TIMEOUT = 1000 * 2; // client time-out
const TCHAR prefix[] = _TEXT( "\\\\.\\pipe\\" );
const DWORD prefix_len = sizeof( prefix ) / sizeof( prefix[0]);
std::basic_string< TCHAR > get_full_name( const TCHAR * name )
{
int len = lstrlen( name );
if ( len >= prefix_len )
{
int cmp = ::CompareString(
LOCALE_SYSTEM_DEFAULT,
NORM_IGNORECASE,
name, prefix_len - 1, // without TERM ZERO !
prefix, prefix_len - 1 // without TERM ZERO !
);
if ( !cmp )
return std::basic_string< TCHAR >( name );
}
return std::basic_string< TCHAR >( prefix ) + name;
}
HANDLE named_pipe( const TCHAR * name )
{
std::basic_string< TCHAR > full_name = get_full_name( name );
HANDLE pipe = INVALID_HANDLE_VALUE;
pipe = ::CreateNamedPipe(
full_name.c_str(),
PIPE_ACCESS_DUPLEX, // read/write access
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // max. instances
DEF_PIPE_BUFSIZE, // output buffer size
DEF_PIPE_BUFSIZE, // input buffer size
DEF_PIPE_TIMEOUT, // client time-out
NULL
);
return pipe;
}
HANDLE detail_create( const TCHAR *name, const pipe_create_params& /* params */ )
{
return named_pipe( name );
}
}
}