本文整理匯總了C++中DisconnectNamedPipe函數的典型用法代碼示例。如果您正苦於以下問題:C++ DisconnectNamedPipe函數的具體用法?C++ DisconnectNamedPipe怎麽用?C++ DisconnectNamedPipe使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DisconnectNamedPipe函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: DisconnectNamedPipe
// Disconnect server or client side of the pipe.
// true - success, false - failure (use GetLastError() for more details)
bool TwoWayPipe::Disconnect()
{
if (m_state == ServerConnected)
{
DisconnectNamedPipe(m_outboundPipe);
DisconnectNamedPipe(m_inboundPipe);
CloseHandle(m_outboundPipe);
m_outboundPipe = INVALID_HANDLE_VALUE;
CloseHandle(m_inboundPipe);
m_inboundPipe = INVALID_HANDLE_VALUE;
m_state = NotInitialized;
return true;
}
else if (m_state == ClientConnected)
{
CloseHandle(m_outboundPipe);
m_outboundPipe = INVALID_HANDLE_VALUE;
CloseHandle(m_inboundPipe);
m_inboundPipe = INVALID_HANDLE_VALUE;
m_state = NotInitialized;
return true;
}
else
{
// nothign to do
return true;
}
}
示例2: select
/* function should be able to tell if bytes are
available and return immediately on overlapped
asynchrounous pipes, like unix select() */
DWORD win32_fifo_read_peek(struct timeval *tv)
{
DWORD ret = 0;
DWORD err, timer;
timer = (tv) ? tv -> tv_sec * 1000 : INFINITE;
debug1("Peeking on pipe handle %p", fifohandle);
SetLastError(0);
if(!fifohandle) return 0;
PeekNamedPipe(fifohandle, NULL, 0, NULL, &ret, NULL);
err = GetLastError();
debug1("Waiting %ld msec for pipe to be ready", timer);
debug1("GetLastError was %ld", err);
if(err == ERROR_BROKEN_PIPE)
{
debug("Broken pipe, disconnecting");
DisconnectNamedPipe(fifohandle);
ConnectNamedPipe(fifohandle,&ov1);
WaitForSingleObjectEx(fifohandle,timer,TRUE);
}
else if(err == ERROR_BAD_PIPE)
{
debug("Bad pipe, Waiting for connect");
DisconnectNamedPipe(fifohandle);
ConnectNamedPipe(fifohandle,&ov1);
WaitForSingleObjectEx(fifohandle,timer,TRUE);
}
debug2("peek %ld bytes, error %ld",ret, err);
return ret;
}
示例3: main
int main() {
HANDLE f1, f2;
char s[128];
DWORD x;
printf("I am the server \n");
// creating pipes
f1=CreateNamedPipe(TEXT("\\\\.\\PIPE\\fifo1"), PIPE_ACCESS_INBOUND,PIPE_TYPE_BYTE|PIPE_WAIT, 3, 0, 0, 0, NULL);
f2=CreateNamedPipe(TEXT("\\\\.\\PIPE\\fifo2"), PIPE_ACCESS_OUTBOUND,PIPE_TYPE_BYTE|PIPE_WAIT, 3, 0, 0, 0, NULL);
ConnectNamedPipe(f1, NULL);
ConnectNamedPipe(f2, NULL);
// reading from pipe
x = 0;
if (ReadFile(f1, s, sizeof(s), &x, NULL)==0) {
printf("reading error.. %d\n", x);
}
printf("read from pipe: %s\n", s);
// writing to pipe
strcpy(s, "Howdy!\n");
if (WriteFile(f2, s, strlen(s)+1, &x, NULL)==0) {
printf("writing error..%d\n", x);
}
// close pipes
DisconnectNamedPipe(f1);
DisconnectNamedPipe(f2);
CloseHandle(f1);
CloseHandle(f2);
}
示例4: PPL_DECLARE
PPL_DECLARE (int) ppl_pipe_close (ppl_pipe_t * apipe)
{
if (apipe == NULL)
return -1;
DisconnectNamedPipe (apipe->pipes[0]);
DisconnectNamedPipe (apipe->pipes[1]);
CloseHandle(apipe->pipes[0]);
CloseHandle(apipe->pipes[1]);
osip_free (apipe);
return 0;
}
示例5: Sleep
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);
}
}
示例6: FlushFileBuffers
void Channel::Destroy()
{
if (m_creator)
{
FlushFileBuffers(m_pipe);
DisconnectNamedPipe(m_pipe);
m_creator = false;
}
if (m_doneEvent != INVALID_HANDLE_VALUE)
{
// Signal the done event so that if we're currently blocked reading,
// we'll stop.
SetEvent(m_doneEvent);
CloseHandle(m_doneEvent);
m_doneEvent = INVALID_HANDLE_VALUE;
}
if (m_readEvent != INVALID_HANDLE_VALUE)
{
CloseHandle(m_readEvent);
m_readEvent = INVALID_HANDLE_VALUE;
}
if (m_pipe != INVALID_HANDLE_VALUE)
{
CloseHandle(m_pipe);
m_pipe = INVALID_HANDLE_VALUE;
}
}
示例7: win_close_ptty
file_error win_close_ptty(osd_file *file)
{
FlushFileBuffers(file->handle);
DisconnectNamedPipe(file->handle);
CloseHandle(file->handle);
return FILERR_NONE;
}
示例8: PipeThreadMonitor
DWORD WINAPI PipeThreadMonitor(LPVOID Arg)
{
IPCPacket packet;
for (;;)
{
// Wait for the client to connect
if (!ConnectNamedPipe(g_Pipe, nullptr))
{
printf("An error occurred while waiting for a client connection\n");
return 1;
}
for (bool runloop = true; runloop;)
{
// Wait for a client message to be sent
if (!ReadFromPipe(&packet))
{
printf("Failed to read from client connection\n");
runloop = false;
break;
}
// Handle the message here
switch (packet.MessageType)
{
case VM_CLIENT_READMEM_CMD:
VmHandleReadMem(&packet);
break;
case VM_CLIENT_WRITEMEM_CMD:
VmHandleWriteMem(&packet);
break;
case VM_CLIENT_SHUTDOWN_CMD:
printf("GOT A SHUTDOWN MESSAGE TYPE\n");
// Exit the loop
runloop = false;
break;
default:
printf("GOT AN UNKNOWN MESSAGE TYPE\n");
packet.Status = 0;
break;
}
// Send the resulting packet
if (!WriteToPipe(&packet))
return 1;
}
// Disconnect the client
DisconnectNamedPipe(g_Pipe);
}
return 0;
}
示例9: while
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;
}
示例10: _efl_net_socket_windows_handle_close
static void
_efl_net_socket_windows_handle_close(HANDLE h)
{
if (!FlushFileBuffers(h))
{
DWORD win32err = GetLastError();
if (win32err != ERROR_PIPE_NOT_CONNECTED)
{
char *msg = _efl_net_windows_error_msg_get(GetLastError());
WRN("HANDLE=%p could not flush buffers: %s", h, msg);
free(msg);
}
}
if (!DisconnectNamedPipe(h))
{
DWORD win32err = GetLastError();
if ((win32err != ERROR_NOT_SUPPORTED) && /* dialer socket don't support it */
(win32err != ERROR_PIPE_NOT_CONNECTED))
{
char *msg = _efl_net_windows_error_msg_get(win32err);
WRN("HANDLE=%p could not disconnect: %s", h, msg);
free(msg);
}
}
CloseHandle(h);
DBG("HANDLE=%p closed", h);
}
示例11: fcgi_close
static inline void fcgi_close(fcgi_request *req, int force, int destroy)
{
if (destroy) {
zend_hash_destroy(&req->env);
}
#ifdef _WIN32
if (is_impersonate) {
RevertToSelf();
}
#endif
if ((force || !req->keep) && req->fd >= 0) {
#ifdef _WIN32
HANDLE pipe = (HANDLE)_get_osfhandle(req->fd);
if (!force) {
FlushFileBuffers(pipe);
}
DisconnectNamedPipe(pipe);
#else
if (!force) {
char buf[8];
shutdown(req->fd, 1);
while (recv(req->fd, buf, sizeof(buf), 0) > 0) {}
}
close(req->fd);
#endif
req->fd = -1;
}
}
示例12: DisconnectNamedPipe
void CPipeBase::ClosePipe()
{
if (m_hPipeClient != INVALID_HANDLE_VALUE)
{
DisconnectNamedPipe( m_hPipeClient );
CloseHandle(m_hPipeClient);
m_hPipeClient = INVALID_HANDLE_VALUE;
}
if (m_hPipeServer != INVALID_HANDLE_VALUE)
{
DisconnectNamedPipe( m_hPipeServer );
CloseHandle(m_hPipeServer);
m_hPipeServer = INVALID_HANDLE_VALUE;
}
}
示例13: 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;
}
示例14: 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;
}
}
}
示例15: close_client_connection
static void close_client_connection(NVQRConnection c)
{
#if defined (_WIN32)
DisconnectNamedPipe(c.client_handle);
#else
#endif
}