Fixed missing callbacks for named pipes.

This commit is contained in:
Armin Novak 2015-03-14 00:34:44 +01:00
parent cb27703d2e
commit 0201f61d19
2 changed files with 63 additions and 10 deletions

View File

@ -111,6 +111,62 @@ BOOL PipeCloseHandle(HANDLE handle) {
return TRUE;
}
static BOOL NamedPipeCloseHandle(HANDLE handle);
static BOOL NamedPipeIsHandled(HANDLE handle)
{
WINPR_NAMED_PIPE* pPipe = (WINPR_NAMED_PIPE*) handle;
if (!pPipe || pPipe->Type != HANDLE_TYPE_NAMED_PIPE)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
return TRUE;
}
static int NamedPipeGetFd(HANDLE handle)
{
WINPR_NAMED_PIPE *pipe = (WINPR_NAMED_PIPE *)handle;
if (!NamedPipeIsHandled(handle))
return -1;
if (pipe->ServerMode)
return pipe->serverfd;
return pipe->clientfd;
}
BOOL NamedPipeCloseHandle(HANDLE handle) {
WINPR_NAMED_PIPE* pNamedPipe = (WINPR_NAMED_PIPE *)handle;
if (!NamedPipeIsHandled(handle))
return FALSE;
if (pNamedPipe->pfnUnrefNamedPipe)
pNamedPipe->pfnUnrefNamedPipe(pNamedPipe);
if (pNamedPipe->name)
free(pNamedPipe->name);
if (pNamedPipe->lpFileName)
free((void*)pNamedPipe->lpFileName);
if (pNamedPipe->lpFilePath)
free((void*)pNamedPipe->lpFilePath);
if (pNamedPipe->serverfd != -1)
close(pNamedPipe->serverfd);
if (pNamedPipe->clientfd != -1)
close(pNamedPipe->clientfd);
free(handle);
return TRUE;
}
static void InitWinPRPipeModule()
{
if (g_NamedPipeServerSockets)
@ -252,6 +308,9 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD
pNamedPipe->dwFlagsAndAttributes = dwOpenMode;
pNamedPipe->clientfd = -1;
pNamedPipe->ServerMode = TRUE;
pNamedPipe->cb.GetFd = NamedPipeGetFd;
pNamedPipe->cb.CloseHandle = NamedPipeCloseHandle;
pNamedPipe->cb.IsHandled = NamedPipeIsHandled;
ArrayList_Lock(g_NamedPipeServerSockets);
for (index = 0; index < ArrayList_Count(g_NamedPipeServerSockets); index++)
@ -347,13 +406,7 @@ out:
if (hNamedPipe == INVALID_HANDLE_VALUE)
{
if (pNamedPipe)
{
free((void*)pNamedPipe->name);
free((void*)pNamedPipe->lpFileName);
free((void*)pNamedPipe->lpFilePath);
free(pNamedPipe);
}
NamedPipeCloseHandle(hNamedPipe);
if (serverfd != -1)
close(serverfd);

View File

@ -47,9 +47,9 @@ struct winpr_named_pipe
int clientfd;
int serverfd;
const char* name;
const char* lpFileName;
const char* lpFilePath;
char* name;
char* lpFileName;
char* lpFilePath;
BOOL ServerMode;
DWORD dwOpenMode;