libwinpr-pipe: initial basic named pipe support

This commit is contained in:
Marc-André Moreau 2013-07-22 23:17:08 -04:00
parent 65bc944def
commit 507899ade9
4 changed files with 18 additions and 8 deletions

View File

@ -204,10 +204,7 @@ HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
status = connect(pNamedPipe->clientfd, (struct sockaddr*) &s, sizeof(struct sockaddr_un));
if (status != 0)
{
printf("connect: %d\n", status);
return INVALID_HANDLE_VALUE;
}
return hNamedPipe;
}

View File

@ -143,6 +143,12 @@ BOOL CloseHandle(HANDLE hObject)
pipe = (WINPR_NAMED_PIPE*) Object;
if (pipe->clientfd != -1)
close(pipe->clientfd);
if (pipe->serverfd != -1)
close(pipe->serverfd);
free(Object);
return TRUE;

View File

@ -240,10 +240,7 @@ BOOL ConnectNamedPipe(HANDLE hNamedPipe, LPOVERLAPPED lpOverlapped)
status = accept(pNamedPipe->serverfd, (struct sockaddr*) &s, &length);
if (status < 0)
{
printf("accept: %d\n", status);
return FALSE;
}
pNamedPipe->clientfd = status;
@ -256,6 +253,12 @@ BOOL DisconnectNamedPipe(HANDLE hNamedPipe)
pNamedPipe = (WINPR_NAMED_PIPE*) hNamedPipe;
if (pNamedPipe->clientfd != -1)
{
close(pNamedPipe->clientfd);
pNamedPipe->clientfd = -1;
}
return TRUE;
}

View File

@ -48,7 +48,7 @@ static void* named_pipe_client_thread(void* arg)
lpNumberOfBytesWritten = 0;
nNumberOfBytesToWrite = PIPE_BUFFER_SIZE;
FillMemory(lpWriteBuffer, 0xAB, PIPE_BUFFER_SIZE);
FillMemory(lpWriteBuffer, PIPE_BUFFER_SIZE, 0x59);
fSuccess = WriteFile(hNamedPipe, lpWriteBuffer, nNumberOfBytesToWrite, &lpNumberOfBytesWritten, NULL);
@ -77,6 +77,8 @@ static void* named_pipe_client_thread(void* arg)
free(lpReadBuffer);
free(lpWriteBuffer);
CloseHandle(hNamedPipe);
return NULL;
}
@ -143,7 +145,7 @@ static void* named_pipe_server_thread(void* arg)
lpNumberOfBytesWritten = 0;
nNumberOfBytesToWrite = PIPE_BUFFER_SIZE;
FillMemory(lpWriteBuffer, 0xCD, PIPE_BUFFER_SIZE);
FillMemory(lpWriteBuffer, PIPE_BUFFER_SIZE, 0x45);
fSuccess = WriteFile(hNamedPipe, lpWriteBuffer, nNumberOfBytesToWrite, &lpNumberOfBytesWritten, NULL);
@ -156,6 +158,8 @@ static void* named_pipe_server_thread(void* arg)
free(lpReadBuffer);
free(lpWriteBuffer);
CloseHandle(hNamedPipe);
return NULL;
}