您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ ConnectNamedPipe函数代码示例

51自学网 2021-06-01 20:13:21
  C++
这篇教程C++ ConnectNamedPipe函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中ConnectNamedPipe函数的典型用法代码示例。如果您正苦于以下问题:C++ ConnectNamedPipe函数的具体用法?C++ ConnectNamedPipe怎么用?C++ ConnectNamedPipe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了ConnectNamedPipe函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;	}
开发者ID:profdevi,项目名称:MPipeServer,代码行数:26,


示例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;}
开发者ID:iSECPartners,项目名称:DIBF,代码行数:27,


示例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;      }  }}
开发者ID:WASSUM,项目名称:longene_travel,代码行数:30,


示例4: connect_pipe

// References:// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365588(v=vs.85).aspxstatic HANDLEconnect_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;}
开发者ID:cloudwu,项目名称:freeabc,代码行数:34,


示例5: 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;}
开发者ID:dingdada,项目名称:tain335,代码行数:30,


示例6: 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;}
开发者ID:ezEngine,项目名称:ezEngine,代码行数:31,


示例7: CommunicationPoolThread

// Communicaton Thread Pool, handles the incoming xCmd.exe requestsvoid 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);        }    }}
开发者ID:piratkin,项目名称:rcmd,代码行数:35,


示例8: 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;}
开发者ID:saluber,项目名称:UIforETW,代码行数:29,


示例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,


示例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,


示例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());            }        }    }
开发者ID:chronos38,项目名称:libipc-,代码行数:34,


示例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,


示例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;}
开发者ID:dacci,项目名称:madoka,代码行数:32,


示例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);	}}
开发者ID:XtrmJosh,项目名称:Piper,代码行数:27,


示例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));}
开发者ID:murank,项目名称:TortoiseGitMod,代码行数:25,


示例16: while

bool GWCAServer::ListenConnections(){	bool bConnected = false;	HANDLE hPipe = NULL;	port.Create(1);	while (true)	{		Sleep(0);		hPipe = CreateNamedPipe(			m_cPipeName,			PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,			PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,			PIPE_UNLIMITED_INSTANCES,			BUFSIZE, BUFSIZE,			1000, NULL);		bConnected = (ConnectNamedPipe(hPipe, 0) == 1) ? true : (GetLastError() == ERROR_PIPE_CONNECTED);		if(bConnected){			port.AssociateFile(hPipe, (ULONG_PTR)hPipe);			LPPIPEINST pOverlapped = (LPPIPEINST)GlobalAlloc(GPTR, sizeof(PIPEINST));			ReadFile(hPipe,				&pOverlapped->bmRequest,				sizeof(pOverlapped->bmRequest),				&pOverlapped->cbRead,				(LPOVERLAPPED)pOverlapped);		}else{			CloseHandle(hPipe);		}	}	return true;}
开发者ID:daewoolanos,项目名称:gwca,代码行数:34,


示例17: pipeThread

void __stdcall Watcher::pipeThread(Watcher *w){	for (;;) {		HANDLE pipe = w->pipe;		WORD rv, myv = Base::instance()->getNVersion();		DWORD rd;		WORD cmd;		if (!ConnectNamedPipe(pipe, NULL)) {			Sleep(1000);			continue;		}		ReadFile(pipe, &cmd, sizeof(cmd), &rd, NULL);		WriteFile(pipe, &myv, sizeof(myv), &rd, NULL);		if (!cmd) {			ReadFile(pipe, &rv, sizeof(rv), &rd, NULL);			if (HIBYTE(rv) > HIBYTE(myv) || (HIBYTE(rv) == HIBYTE(myv) && LOBYTE(rv) > LOBYTE(myv))) {				w->terminate();				return;			}		} else {			char file[MAX_PATH + 1];			ReadFile(pipe, file, sizeof(file), &rd, NULL);			file[MAX_PATH] = 0;			log(LL_DIAG, L_NEW L_DEL L_COMMAND "%s", file);			Sleep(6000);			Base::instance()->forceDeleteFile(std::string(file));		}				DisconnectNamedPipe(pipe);	}}
开发者ID:Avalonxy,项目名称:malware-1,代码行数:32,


示例18: _ecore_con_local_win32_listening

static unsigned int __stdcall_ecore_con_local_win32_listening(void *data){   Ecore_Con_Server *svr;   BOOL res;   svr = (Ecore_Con_Server *)data;   while (1)     {        res = ConnectNamedPipe(svr->pipe, NULL);        if (!res)          {             ERR("Opening the connection to the client failed");             CloseHandle(svr->pipe);             svr->pipe = NULL;          }        break;     }   DBG("Client connected");   printf(" ### %s/n", __FUNCTION__);   _endthreadex(0);   return 0;}
开发者ID:roman5566,项目名称:EFL-PS3,代码行数:26,


示例19: pipe_listener

unsigned WINAPI pipe_listener(void *parameters) {    while(1) {        HANDLE pipe =  CreateNamedPipe(                        pipeName,                        PIPE_ACCESS_DUPLEX,                        PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,                        PIPE_UNLIMITED_INSTANCES,                        PIPE_BUFSIZE,                        PIPE_BUFSIZE,                        0,                        NULL);        BOOL clientConnected;        if( pipe == INVALID_HANDLE_VALUE ) {            printf("Error creating named pipe. Code %lu/n", GetLastError());            return -1;        }        // True if client connects *after* server called ConnectNamedPipe         // or *between* CreateNamedPipe and ConnectNamedPipe        clientConnected =             ConnectNamedPipe(pipe, NULL) ? TRUE : GetLastError()==ERROR_PIPE_CONNECTED;        printf("Client connected!/n");        if( !clientConnected ) {            printf("Failure while listening for clients. Code %lu/n", GetLastError());            CloseHandle(pipe);            return -1;        }        printf("Create client thread/n");        _beginthreadex(NULL, 0, fifo_rx, (PVOID)pipe, 0, 0);        }    return 0;}
开发者ID:AdamPrzybyla,项目名称:libcsp,代码行数:34,


示例20: CreateNamedPipe

void WinListener::create_pipe(){    _pipe = CreateNamedPipe(_pipename, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,                            PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,                            PIPE_UNLIMITED_INSTANCES, PIPE_BUF_SIZE, PIPE_BUF_SIZE,                            PIPE_TIMEOUT, NULL);    if (_pipe == INVALID_HANDLE_VALUE) {        THROW("CreateNamedPipe() failed %u", GetLastError());    }    if (ConnectNamedPipe(_pipe, &_overlap)) {        THROW("ConnectNamedPipe() is not pending");    }    switch (GetLastError()) {    case ERROR_IO_PENDING:        DBG(0, "Pipe waits for connection");        break;    case ERROR_PIPE_CONNECTED: {        DBG(0, "Pipe already connected");        WinConnection *con = new WinConnection(_pipe, _process_loop);        NamedPipe::ConnectionInterface &con_interface = _listener_interface.create();        con->set_handler(&con_interface);        con_interface.bind((NamedPipe::ConnectionRef)con);        create_pipe();        break;    }    default:        THROW("ConnectNamedPipe() failed %u", GetLastError());    }}
开发者ID:colama,项目名称:colama-3rdparty-tools,代码行数:29,


示例21: npipe_input_open

static int npipe_input_open(const char *pipe_name){  static OVERLAPPED overlapped;  static HANDLE hEvent;  char PipeName[256];  DWORD ret;  hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); memset( &overlapped, 0, sizeof(OVERLAPPED)); overlapped.hEvent = hEvent;	  sprintf(PipeName, "////.//pipe//%s", pipe_name);  hPipe = CreateNamedPipe(PipeName, PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED, //    PIPE_WAIT|  	PIPE_READMODE_BYTE |PIPE_TYPE_BYTE, 2,    0, PIPE_BUFFER_SIZE, 0, NULL);  if (hPipe == INVALID_HANDLE_VALUE) {    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Can't create Named Pipe %s : %ld",    	pipe_name, GetLastError()); 	return -1;  }  ret = ConnectNamedPipe(hPipe, &overlapped);	if ( (ret == 0)  && (ERROR_IO_PENDING!=GetLastError()) ){    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "CnnectNamePipe(%ld) error %s",    	GetLastError(), pipe_name);        CloseHandle(hPipe);  	    hPipe=NULL;        return -1;   }//	WaitForSingleObject(overlapped.hEvent, 1000);	CloseHandle(hEvent);  return 0;}
开发者ID:Distrotech,项目名称:TiMidity,代码行数:34,


示例22: LocalAlloc

BOOL CNeighbour::Connect(LPCTSTR lpPipeName, DWORD nMaxInstances, DWORD nTimeOut){	if ( m_hPipe != INVALID_HANDLE_VALUE ) return FALSE;		SECURITY_ATTRIBUTES sa;	PSECURITY_DESCRIPTOR pSD;		pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,SECURITY_DESCRIPTOR_MIN_LENGTH);	if ( ! InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION) )	{		LocalFree( (HLOCAL)pSD ); return FALSE;	}	if ( ! SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE) )	{		LocalFree( (HLOCAL)pSD ); return FALSE;	}		sa.nLength = sizeof(sa);	sa.lpSecurityDescriptor = pSD; 	sa.bInheritHandle = TRUE;	m_hPipe = CreateNamedPipe( lpPipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,		PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, nMaxInstances, TEMP_BUFFER, TEMP_BUFFER, nTimeOut, &sa );		if ( m_hPipe == INVALID_HANDLE_VALUE ) return FALSE;		ZeroMemory( &m_pOverlapped, sizeof(OVERLAPPED) );	m_pOverlapped.hEvent = m_pWakeup;		ConnectNamedPipe( m_hPipe, &m_pOverlapped );TRACE("CreateNamedPipe: %s/n", lpPipeName);		StartThread();	return TRUE;}
开发者ID:pics860,项目名称:callcenter,代码行数:35,


示例23: MSTP_Get_Send

/* Return: amount of PDU data */uint16_t MSTP_Get_Send(    volatile struct mstp_port_struct_t * mstp_port,    unsigned timeout){       /* milliseconds to wait for a packet */    (void) mstp_port;    (void) timeout;    return 0;}uint16_t MSTP_Get_Reply(    volatile struct mstp_port_struct_t * mstp_port,    unsigned timeout){       /* milliseconds to wait for a packet */    (void) mstp_port;    (void) timeout;    return 0;}static char Capture_Filename[32] = "mstp_20090123091200.cap";static FILE *pFile = NULL;      /* stream pointer */#if defined(_WIN32)static HANDLE hPipe = INVALID_HANDLE_VALUE;     /* pipe handle */static void named_pipe_create(    char *pipe_name){    fprintf(stdout, "mstpcap: Creating Named Pipe /"%s/"/n", pipe_name);    /* create the pipe */    while (hPipe == INVALID_HANDLE_VALUE)    {        /* use CreateFile rather than CreateNamedPipe */        hPipe = CreateFile(            pipe_name,            GENERIC_READ |            GENERIC_WRITE,            0,            NULL,            OPEN_EXISTING,            0,            NULL);        if (hPipe != INVALID_HANDLE_VALUE) {            break;        }        /* if an error occured at handle creation */        if (!WaitNamedPipe(pipe_name, 20000)) {            printf("Could not open pipe: waited for 20sec!/n"                "If this message was issued before the 20sec finished,/n"                "then the pipe doesn't exist!/n");            Exit_Requested = true;            return;        }    }    ConnectNamedPipe(hPipe, NULL);}
开发者ID:edwardwhittle,项目名称:hello_world,代码行数:54,


示例24: open_windows_pipe

static HANDLE_OR_FILEPTRopen_windows_pipe(const char *filename){#ifdef WIN32	HANDLE pipe;	int result;	pipe = CreateNamedPipe(filename,		PIPE_ACCESS_OUTBOUND,          // write-only		PIPE_TYPE_MESSAGE | PIPE_WAIT, // blocking writes		1,                             // only allow one pipe		70000,          // write buffer. GTH max is 64k		10000,          // read buffer. We don't read		0,              // default timeout		0);             // no security attributes	if (pipe == INVALID_HANDLE_VALUE) {		die("Unable to create a named pipe. Giving up.");	}	result = ConnectNamedPipe(pipe, 0);	if (!result) {		die("Unabled to connect the named pipe. Giving up.");	}	return pipe;#else	die("Cannot open a windows named pipe on a non-windows OS. Giving up.");	return 0;#endif}
开发者ID:GemikGmbH,项目名称:Corelatus-GTH-example-code,代码行数:31,


示例25: _ecore_con_local_win32_listening

static unsigned int __stdcall_ecore_con_local_win32_listening(void *data){   Ecore_Con_Server *obj = data;   Ecore_Con_Server_Data *svr = eo_data_scope_get(obj, ECORE_CON_SERVER_CLASS);   BOOL res;   while (1)     {        res = ConnectNamedPipe(svr->pipe, NULL);        if (!res)          {             ERR("Opening the connection to the client failed");             CloseHandle(svr->pipe);             svr->pipe = NULL;          }        break;     }   DBG("Client connected");   printf(" ### %s/n", __FUNCTION__);   _endthreadex(0);   return 0;}
开发者ID:tguillem,项目名称:efl,代码行数:25,


示例26: CreateNamedPipeA

void WritePipe::setup_pipe(){	// Create a pipe to send data	_pipe = CreateNamedPipeA(		_pipe_name.c_str(), // name of the pipe		PIPE_ACCESS_OUTBOUND, // 1-way pipe -- send only		PIPE_TYPE_BYTE | PIPE_WAIT, // send data as a byte stream		1, // only allow 1 instance of this pipe		0, // no outbound buffer		0, // no inbound buffer		10, // use default wait time		NULL // use default security attributes		);	if (_pipe == NULL || _pipe == INVALID_HANDLE_VALUE) 	{		traceerr("Failed to create outbound pipe instance.");		return;	}	bool result = ConnectNamedPipe(_pipe, NULL);	if (!result)	{		traceerr( "Failed to make connection on named pipe.");		CloseHandle(_pipe); // close the pipe		return;	}	running = true;}
开发者ID:nonametr,项目名称:mls,代码行数:27,


示例27: processSpeechInput

voidprocessSpeechInput (SpeechSynthesizer *spk) {#if defined(__MINGW32__)  if (speechInputHandle != INVALID_HANDLE_VALUE) {    if (speechInputConnected ||        (speechInputConnected = ConnectNamedPipe(speechInputHandle, NULL)) ||        (speechInputConnected = (GetLastError() == ERROR_PIPE_CONNECTED))) {      char buffer[0X1000];      DWORD count;      if (ReadFile(speechInputHandle, buffer, sizeof(buffer), &count, NULL)) {        if (count) sayCharacters(spk, buffer, count, 0);      } else {        DWORD error = GetLastError();        if (error != ERROR_NO_DATA) {          speechInputConnected = 0;          DisconnectNamedPipe(speechInputHandle);          if (error != ERROR_BROKEN_PIPE)            logWindowsSystemError("speech input FIFO read");        }      }    }  }#elif defined(S_ISFIFO)  if (speechInputDescriptor != -1) {    char buffer[0X1000];    int count = read(speechInputDescriptor, buffer, sizeof(buffer));    if (count > 0) sayCharacters(spk, buffer, count, 0);  }#endif /* process speech input */}
开发者ID:Kartofelna,项目名称:brltty,代码行数:33,


示例28: monitorWindowsPipeConnect

static intmonitorWindowsPipeConnect (NamedPipeObject *obj) {    if (ResetEvent(obj->windows.connect.event)) {        ZeroMemory(&obj->windows.connect.overlapped, sizeof(obj->windows.connect.overlapped));        obj->windows.connect.overlapped.hEvent = obj->windows.connect.event;        if (ConnectNamedPipe(obj->input.descriptor, &obj->windows.connect.overlapped)) {            if (doWindowsPipeConnected(obj)) {                return 1;            }        } else {            DWORD error = GetLastError();            if (error == ERROR_PIPE_CONNECTED) {                if (doWindowsPipeConnected(obj)) {                    return 1;                }            } else if (error == ERROR_IO_PENDING) {                if (asyncMonitorFileInput(&obj->windows.connect.monitor, obj->windows.connect.event, handleWindowsPipeConnected, obj)) {                    return 1;                }            } else {                logWindowsError(error, "ConnectNamedPipe");            }        }    } else {        logWindowsSystemError("ResetEvent");    }    return 0;}
开发者ID:plundblad,项目名称:brltty,代码行数:31,


示例29: BALL_LOG_SET_CATEGORY

int PipeControlChannel::readNamedPipe(){    BALL_LOG_SET_CATEGORY(LOG_CATEGORY);    BSLS_ASSERT(INVALID_HANDLE_VALUE != d_impl.d_windows.d_handle);    BALL_LOG_TRACE << "Accepting next pipe client connection" << BALL_LOG_END;    if (!ConnectNamedPipe(d_impl.d_windows.d_handle, NULL)) {        BALL_LOG_TRACE << "Connecting to named pipe '" << d_pipeName                       << "': "                       << describeWin32Error(GetLastError())                       << BALL_LOG_END;        DWORD lastError = GetLastError();        if (lastError != ERROR_PIPE_CONNECTED && lastError != ERROR_NO_DATA) {            BALL_LOG_TRACE << "Failed to connect to named pipe '" << d_pipeName                           << "'"                           << BALL_LOG_END;            return -1;        }    }    while(1) {        char buffer[MAX_PIPE_BUFFER_LEN];        DWORD bytesRead = 0;        if (ReadFile(d_impl.d_windows.d_handle,                     buffer,                     MAX_PIPE_BUFFER_LEN,                     &bytesRead,                     NULL))        {           if (bytesRead > 0) {               if (buffer[bytesRead - 1] == '/n') {                   bytesRead--;               }               bslstl::StringRef stringRef(buffer, bytesRead);               if (!stringRef.isEmpty()) {                   d_callback(stringRef);               }           }           else {              // reached EOF on a named pipe.              break;           }        }        else {            BALL_LOG_TRACE << "Failed to read from named pipe '" << d_pipeName                           << "': "                           << describeWin32Error(GetLastError())                           << BALL_LOG_END;            break;        }    }    DisconnectNamedPipe(d_impl.d_windows.d_handle);    return 0;}
开发者ID:SuperV1234,项目名称:bde,代码行数:59,


示例30: Connect

    bool Connect()    {        if (!ConnectNamedPipe(hPipe, &Overlapped))            if (GetLastError() != ERROR_IO_PENDING)            {                ImDiskSvcStatus.dwWin32ExitCode = GetLastError();                delete this;                return false;            }        HANDLE hWaitObjects[] =        {            Overlapped.hEvent,            ImDiskSvcStopEvent        };        switch (WaitForMultipleObjects(sizeof(hWaitObjects) /            sizeof(*hWaitObjects),            hWaitObjects,            FALSE,            INFINITE))        {        case WAIT_OBJECT_0:        {            union            {                DWORD(CALLBACK ImDiskSvcServerSession::*Member)();                UINT(CALLBACK *Static)(LPVOID);            } ThreadFunction;            ThreadFunction.Member = &ImDiskSvcServerSession::Thread;            KdPrint(("ImDskSvc: Creating thread.%n"));            UINT id;            HANDLE hThread = (HANDLE)                _beginthreadex(NULL, 0, ThreadFunction.Static, this, 0, &id);            if (hThread == NULL)            {                ImDiskSvcStatus.dwWin32ExitCode = GetLastError();                delete this;                return false;            }            CloseHandle(hThread);            ImDiskSvcStatus.dwWin32ExitCode = NO_ERROR;            return true;        }        case WAIT_OBJECT_0 + 1:            ImDiskSvcStatus.dwWin32ExitCode = NO_ERROR;            delete this;            return false;        default:            ImDiskSvcStatus.dwWin32ExitCode = GetLastError();            delete this;            return false;        }    }
开发者ID:nnaabbcc,项目名称:exercise,代码行数:59,



注:本文中的ConnectNamedPipe函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ ConnectToServer函数代码示例
C++ Conj函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。