本文整理汇总了C++中ConnectNamedPipe函数的典型用法代码示例。如果您正苦于以下问题:C++ ConnectNamedPipe函数的具体用法?C++ ConnectNamedPipe怎么用?C++ ConnectNamedPipe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ConnectNamedPipe函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DisconnectNamedPipe
bool MWinNamedPipeServer::Connect(void)
{
if(mClientConnected==true)
{
DisconnectNamedPipe(mhPipe);
}
if(ConnectNamedPipe(mhPipe,NULL)==FALSE)
{
// It is possible that a client connects before the ConnectNamedPipe is invoked after CreateNamed Pipe.
// Connections is still good!
// Ref: https://msdn.microsoft.com/query/dev15.query?appId=Dev15IDEF1&l=EN-US&k=k(NAMEDPIPEAPI%2FConnectNamedPipe);k(ConnectNamedPipe);k(DevLang-C%2B%2B);k(TargetOS-Windows)&rd=true
DWORD error=GetLastError();
if(error==ERROR_PIPE_CONNECTED)
{
mClientConnected=true;
return true;
}
mClientConnected=false;
return false;
}
mClientConnected=true;
return true;
}
示例2: CreateNamedPipe
BOOL NamedPipeInputFuzzer::Init()
{
BOOL bResult=FALSE;
dibf_pipe = CreateNamedPipe(_T("\\\\.\\pipe\\dibf_pipe"),
PIPE_ACCESS_INBOUND,
PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE|PIPE_WAIT|PIPE_REJECT_REMOTE_CLIENTS,
1,
MAX_BUFSIZE/2,
MAX_BUFSIZE/2,
0,
NULL);
if(dibf_pipe!=INVALID_HANDLE_VALUE) {
TPRINT(VERBOSITY_DEFAULT, _T("Named pipe created, waiting for connection...\n"));
if(ConnectNamedPipe(dibf_pipe, NULL)?TRUE:(GetLastError()==ERROR_PIPE_CONNECTED)) {
TPRINT(VERBOSITY_DEFAULT, _T("Fuzzing client connected to named pipe\n"));
inputThread = CreateThread(NULL, 0, FuzzInputProc, this, 0, NULL);
if(inputThread) {
bResult = TRUE;
}
else {
TPRINT(VERBOSITY_ERROR, _T("Failed to create fuzz input thread with error %#.8x\n"), GetLastError());
}
}
}
return bResult;
}
示例3: rpcrt4_conn_listen_pipe
static RPC_STATUS rpcrt4_conn_listen_pipe(RpcConnection_np *npc)
{
if (npc->listening)
return RPC_S_OK;
npc->listening = TRUE;
for (;;)
{
if (ConnectNamedPipe(npc->pipe, &npc->ovl))
return RPC_S_OK;
switch(GetLastError())
{
case ERROR_PIPE_CONNECTED:
SetEvent(npc->ovl.hEvent);
return RPC_S_OK;
case ERROR_IO_PENDING:
/* will be completed in rpcrt4_protseq_np_wait_for_new_connection */
return RPC_S_OK;
case ERROR_NO_DATA_DETECTED:
/* client has disconnected, retry */
DisconnectNamedPipe( npc->pipe );
break;
default:
npc->listening = FALSE;
WARN("Couldn't ConnectNamedPipe (error was %d)\n", GetLastError());
return RPC_S_OUT_OF_RESOURCES;
}
}
}
示例4: connect_pipe
// References:
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365588(v=vs.85).aspx
static HANDLE
connect_pipe(const char* app_name) {
HANDLE pipe = INVALID_HANDLE_VALUE;
char username[UNLEN + 1];
DWORD unlen = UNLEN + 1;
if (GetUserNameA(username, &unlen)) {
// add username to the pipe path so it will not clash with other users' pipes.
char pipe_name[MAX_PATH];
sprintf(pipe_name, "\\\\.\\pipe\\%s\\%s_pipe", username, app_name);
const size_t buffer_size = 1024;
// create the pipe
pipe = CreateNamedPipeA(pipe_name,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
buffer_size,
buffer_size,
NMPWAIT_USE_DEFAULT_WAIT,
&g_securityAttributes);
if (pipe != INVALID_HANDLE_VALUE) {
// try to connect to the named pipe
// NOTE: this is a blocking call
if (FALSE == ConnectNamedPipe(pipe, NULL)) {
// fail to connect the pipe
CloseHandle(pipe);
pipe = INVALID_HANDLE_VALUE;
}
}
}
return pipe;
}
示例5: ListenerThread
DWORD ChildProcess::ListenerThread()
{
// wait for someone to connect to the pipe
if (ConnectNamedPipe(hPipe_, NULL) || GetLastError() == ERROR_PIPE_CONNECTED)
{
// Acquire the lock while writing to processOutput_
char buffer[1024];
DWORD dwRead;
while (ReadFile(hPipe_, buffer, sizeof(buffer) - 1, &dwRead, NULL) != FALSE)
{
if (dwRead > 0)
{
CSingleLock locker(&outputLock_);
buffer[dwRead] = 0;
OutputDebugStringA(buffer);
processOutput_ += AnsiToUnicode(buffer);
}
SetEvent(hOutputAvailable_);
}
}
else
{
OutputDebugString(L"Connect failed.\n");
}
DisconnectNamedPipe(hPipe_);
return 0;
}
示例6: win32_fifo_mkfifo
int win32_fifo_mkfifo(const char *path)
{
HANDLE ret;
win32_fifo_close();
#ifdef WANT_WIN32_UNICODE
wchar_t *str;
if(win32_utf8_wide(path,&str,NULL) == 0)
{
fprintf(stderr,"Cannot get FIFO name, likely out of memory\n");
return -1;
}
#if (DEBUG == 1)
fwprintf(stderr,L"CreateNamedPipeW %ws\n", str);
#endif
ret = CreateNamedPipeW(str,PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED,PIPE_TYPE_BYTE,1,255,255,0,NULL);
free(str);
#else
#if (DEBUG == 1)
fprintf(stderr,"CreateNamedPipeA %s\n", path);
#endif
ret = CreateNamedPipeA(path,PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED,PIPE_TYPE_BYTE,1,255,255,0,NULL);
#endif /* WANT_WIN32_UNICODE */
if(ret == INVALID_HANDLE_VALUE) return -1;
fifohandle = ret;
/* Wait for client */
ConnectNamedPipe(fifohandle,&ov1);
WaitForSingleObjectEx(fifohandle,INFINITE,TRUE);
return 0;
}
示例7: EZ_ASSERT_DEBUG
bool ezPipeChannel_win::ProcessConnection()
{
EZ_ASSERT_DEBUG(m_ThreadId == ezThreadUtils::GetCurrentThreadID(), "Function must be called from worker thread!");
if (m_InputState.IsPending)
m_InputState.IsPending = false;
BOOL res = ConnectNamedPipe(m_PipeHandle, &m_InputState.Context.Overlapped);
if (res)
{
//EZ_REPORT_FAILURE
return false;
}
ezUInt32 error = GetLastError();
switch (error)
{
case ERROR_IO_PENDING:
m_InputState.IsPending = true;
break;
case ERROR_PIPE_CONNECTED:
m_Connected = true;
break;
case ERROR_NO_DATA:
return false;
default:
ezLog::Error("Could not connect to pipe (Error code: {0})", ezArgErrorCode(error));
return false;
}
return true;
}
示例8: CommunicationPoolThread
// Communicaton Thread Pool, handles the incoming xCmd.exe requests
void CommunicationPoolThread(PVOID)
{
HANDLE hPipe = NULL;
for (;;)
{
SECURITY_ATTRIBUTES SecAttrib = {0};
SECURITY_DESCRIPTOR SecDesc;
InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&SecDesc, TRUE, NULL, TRUE);
SecAttrib.nLength = sizeof(SECURITY_ATTRIBUTES);
SecAttrib.lpSecurityDescriptor = &SecDesc;;
SecAttrib.bInheritHandle = TRUE;
// Create communication pipe
hPipe = CreateNamedPipe(
_T("\\\\.\\pipe\\")XCMDCOMM,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
0,
0,
(DWORD)-1,
&SecAttrib);
if ( hPipe != NULL )
{
// Waiting for client to connect to this pipe
ConnectNamedPipe( hPipe, NULL );
_beginthread( CommunicationPipeThreadProc, 0, (void*)hPipe);
}
}
}
示例9: CWE253_Incorrect_Check_of_Function_Return_Value__char_w32CreateNamedPipe_01_bad
void CWE253_Incorrect_Check_of_Function_Return_Value__char_w32CreateNamedPipe_01_bad()
{
{
char * pipeName = "\\\\.\\pipe\\mypipe";
HANDLE hPipe = INVALID_HANDLE_VALUE;
BOOL fConnected = FALSE;
hPipe = CreateNamedPipeA(
pipeName,
FILE_FLAG_FIRST_PIPE_INSTANCE, /* FILE_FLAG_FIRST_PIPE_INSTANCE - this flag must be set */
PIPE_TYPE_MESSAGE |
PIPE_READMODE_MESSAGE |
PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
BUFFER_SIZE,
BUFFER_SIZE,
NMPWAIT_USE_DEFAULT_WAIT,
NULL);
/* FLAW: If CreateNamedPipeA() failed, the return value will be INVALID_HANDLE_VALUE,
but we are checking to see if the return value is NULL */
if (hPipe == NULL)
{
exit(1);
}
fConnected = ConnectNamedPipe(hPipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
/* We'll leave out most of the implementation since it has nothing to do with the CWE
* and since the checkers are looking for certain function calls anyway */
CloseHandle(hPipe);
}
}
开发者ID:gpwi970725,项目名称:testJuliet1,代码行数:29,代码来源:CWE253_Incorrect_Check_of_Function_Return_Value__char_w32CreateNamedPipe_01.c
示例10: good1
static void good1()
{
{
char * pipeName = "\\\\.\\pipe\\mypipe";
HANDLE hPipe = INVALID_HANDLE_VALUE;
BOOL fConnected = FALSE;
hPipe = CreateNamedPipeA(
pipeName,
FILE_FLAG_FIRST_PIPE_INSTANCE, /* FILE_FLAG_FIRST_PIPE_INSTANCE - this flag must be set */
PIPE_TYPE_MESSAGE |
PIPE_READMODE_MESSAGE |
PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
BUFFER_SIZE,
BUFFER_SIZE,
NMPWAIT_USE_DEFAULT_WAIT,
NULL);
/* FIX: check for the correct return value */
if (hPipe == INVALID_HANDLE_VALUE)
{
exit(1);
}
fConnected = ConnectNamedPipe(hPipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
/* We'll leave out most of the implementation since it has nothing to do with the CWE
* and since the checkers are looking for certain function calls anyway */
CloseHandle(hPipe);
}
}
开发者ID:gpwi970725,项目名称:testJuliet1,代码行数:28,代码来源:CWE253_Incorrect_Check_of_Function_Return_Value__char_w32CreateNamedPipe_01.c
示例11: sizeof
void NamedPipe::Initialize()
{
SECURITY_ATTRIBUTES attr;
attr.bInheritHandle = TRUE;
attr.nLength = sizeof(SECURITY_ATTRIBUTES);
attr.lpSecurityDescriptor = NULL;
mHandle = CreateFileA(
mName.c_str(),
GENERIC_READ | GENERIC_WRITE,
0,
&attr,
OPEN_EXISTING,
0,
NULL);
if (mHandle == INVALID_HANDLE) {
mHandle = CreateNamedPipeA(
mName.c_str(),
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
65536,
65536,
NMPWAIT_WAIT_FOREVER,
&attr);
if (mHandle == INVALID_HANDLE) {
throw NamedPipeException(GetLastErrorString());
} else if (!ConnectNamedPipe(mHandle, NULL) && GetLastError() != ERROR_PIPE_CONNECTED) {
throw NamedPipeException(GetLastErrorString());
}
}
}
示例12: CWE252_Unchecked_Return_Value__char_w32CreateNamedPipe_04_bad
void CWE252_Unchecked_Return_Value__char_w32CreateNamedPipe_04_bad()
{
if(STATIC_CONST_TRUE)
{
{
char * pipeName = "\\\\.\\pipe\\mypipe";
HANDLE hPipe = INVALID_HANDLE_VALUE;
BOOL fConnected = FALSE;
hPipe = CreateNamedPipeA(
pipeName,
FILE_FLAG_FIRST_PIPE_INSTANCE, /* FILE_FLAG_FIRST_PIPE_INSTANCE - this flag must be set */
PIPE_TYPE_MESSAGE |
PIPE_READMODE_MESSAGE |
PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
BUFSIZE,
BUFSIZE,
NMPWAIT_USE_DEFAULT_WAIT,
NULL);
/* FLAW: Do not check the return value */
fConnected = ConnectNamedPipe(hPipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
/* We'll leave out most of the implementation since it has nothing to do with the CWE
* and since the checkers are looking for certain function calls anyway */
CloseHandle(hPipe);
}
}
}
开发者ID:gpwi970725,项目名称:testJuliet1,代码行数:27,代码来源:CWE252_Unchecked_Return_Value__char_w32CreateNamedPipe_04.c
示例13: switch
HRESULT PipeStream::OnCustomRequested(
HandleStream::AsyncContext* handle_context) {
auto context = static_cast<AsyncContext*>(handle_context);
BOOL succeeded;
switch (context->type) {
case PipeRequest::WaitForConnection:
succeeded = ConnectNamedPipe(handle_, context);
break;
case PipeRequest::Transact:
succeeded = TransactNamedPipe(handle_, context->buffer, context->length,
context->buffer2, context->length2, nullptr,
context);
break;
default:
assert(false);
return E_NOTIMPL;
}
DWORD error = GetLastError();
if (!succeeded && error != ERROR_IO_PENDING) {
if (error == ERROR_PIPE_CONNECTED && context->hEvent != NULL)
SetEvent(context->hEvent);
return __HRESULT_FROM_WIN32(error);
}
return S_OK;
}
示例14: GetModuleHandle
Piper::Piper()
{
// Get tibias main module for future use
baseAddress = (DWORD) GetModuleHandle(0);
// Define a pipe name
pipeName = L"\\\\.\\pipe\\piperpipe";
// Create the pipe
hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE, 1, BUFFER_SIZE, BUFFER_SIZE, 5000, NULL);
// If we didn't make it, tell the user something went wrong.
if (hPipe == NULL || hPipe == INVALID_HANDLE_VALUE)
{
MessageBox(NULL, L"Error loading named pipe, please consult your software provider for support", L"Error!", MB_ICONSTOP);
}
// Wait for a client to connect to see the data down the pipe.
ConnectNamedPipe(hPipe, NULL);
// Send a message down the pipe to confirm it's working
Send("SYSTEM OPERATIONAL");
// Send the base address for good measure
char *buff = new char[32];
_itoa_s(baseAddress, buff, strlen(buff), 16);
Send(buff);
for (int i = 0; i < 10; i++)
{
Send("Testing");
Sleep(1000);
}
}
示例15: hPipe
shared_ptr<InterprocessIo> InterprocessServer::Connect()
{
shared_handle hPipe(CreateNamedPipe(
GetPipeName(),
PIPE_ACCESS_DUPLEX | // read/write access
FILE_FLAG_OVERLAPPED,
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_WAIT, // non-blocking mode
PIPE_UNLIMITED_INSTANCES, // max. instances
BUF_SIZE, // output buffer size
BUF_SIZE, // input buffer size
NMPWAIT_USE_DEFAULT_WAIT, // client time-out
NULL) // NULL DACL
);
if(!hPipe) {
return shared_ptr<InterprocessIo>();
}
if(!ConnectNamedPipe(hPipe.get(), NULL) && (GetLastError()!=ERROR_PIPE_CONNECTED)) {
return shared_ptr<InterprocessIo>();
}
return shared_ptr<InterprocessIo>(new InterprocessIo(hPipe));
}