- Fix PeekNamedPipe. Now only 14 winetests fail for pipetest.

- Cleanup DisconnectNamedPipe and fix a small bug in it.

svn path=/trunk/; revision=19088
This commit is contained in:
Alex Ionescu 2005-11-09 04:32:44 +00:00
parent 85f0828a18
commit 2300542dbc

View file

@ -760,12 +760,14 @@ CallNamedPipeW(LPCWSTR lpNamedPipeName,
/*
* @implemented
*/
BOOL STDCALL
BOOL
WINAPI
DisconnectNamedPipe(HANDLE hNamedPipe)
{
IO_STATUS_BLOCK Iosb;
NTSTATUS Status;
/* Send the FSCTL to the driver */
Status = NtFsControlFile(hNamedPipe,
NULL,
NULL,
@ -778,24 +780,21 @@ DisconnectNamedPipe(HANDLE hNamedPipe)
0);
if (Status == STATUS_PENDING)
{
Status = NtWaitForSingleObject(hNamedPipe,
FALSE,
NULL);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return(FALSE);
}
/* Wait on NPFS to finish and get updated status */
Status = NtWaitForSingleObject(hNamedPipe, FALSE, NULL);
if (NT_SUCCESS(Status)) Status = Iosb.Status;
}
/* Check for error */
if (!NT_SUCCESS(Status))
{
/* Fail */
SetLastErrorByStatus(Status);
return(FALSE);
}
return(TRUE);
return FALSE;
}
return TRUE;
}
/*
* @unimplemented
@ -989,11 +988,11 @@ GetNamedPipeInfo(HANDLE hNamedPipe,
return(TRUE);
}
/*
* @implemented
*/
BOOL STDCALL
BOOL
WINAPI
PeekNamedPipe(HANDLE hNamedPipe,
LPVOID lpBuffer,
DWORD nBufferSize,
@ -1006,11 +1005,11 @@ PeekNamedPipe(HANDLE hNamedPipe,
ULONG BufferSize;
NTSTATUS Status;
BufferSize = nBufferSize + sizeof(FILE_PIPE_PEEK_BUFFER);
Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
0,
BufferSize);
/* Calculate the buffer space that we'll need and allocate it */
BufferSize = nBufferSize + FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]);
Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferSize);
/* Tell the driver to seek */
Status = NtFsControlFile(hNamedPipe,
NULL,
NULL,
@ -1023,57 +1022,58 @@ PeekNamedPipe(HANDLE hNamedPipe,
BufferSize);
if (Status == STATUS_PENDING)
{
Status = NtWaitForSingleObject(hNamedPipe,
FALSE,
NULL);
if (NT_SUCCESS(Status))
Status = Iosb.Status;
/* Wait for npfs to be done, and update the status */
Status = NtWaitForSingleObject(hNamedPipe, FALSE, NULL);
if (NT_SUCCESS(Status)) Status = Iosb.Status;
}
if (Status == STATUS_BUFFER_OVERFLOW)
{
Status = STATUS_SUCCESS;
}
/* Overflow is success for us */
if (Status == STATUS_BUFFER_OVERFLOW) Status = STATUS_SUCCESS;
/* If we failed */
if (!NT_SUCCESS(Status))
{
RtlFreeHeap(RtlGetProcessHeap(),
0,
Buffer);
/* Free the buffer and return failure */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
SetLastErrorByStatus(Status);
return(FALSE);
return FALSE;
}
if (lpTotalBytesAvail != NULL)
/* Check if caller requested bytes available */
if (lpTotalBytesAvail) *lpTotalBytesAvail = Buffer->ReadDataAvailable;
/* Check if caller requested bytes read */
if (lpBytesRead)
{
*lpTotalBytesAvail = Buffer->ReadDataAvailable;
/* Calculate the bytes returned, minus our structure overhead */
*lpBytesRead = (ULONG)(Iosb.Information -
FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]));
}
if (lpBytesRead != NULL)
{
*lpBytesRead = Iosb.Information - sizeof(FILE_PIPE_PEEK_BUFFER);
}
if (lpBytesLeftThisMessage != NULL)
/* Check if caller requested bytes left */
if (lpBytesLeftThisMessage)
{
/* Calculate total minus what we returned and our structure overhead */
*lpBytesLeftThisMessage = Buffer->MessageLength -
(Iosb.Information - sizeof(FILE_PIPE_PEEK_BUFFER));
(ULONG)(Iosb.Information -
FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]));
}
if (lpBuffer != NULL)
/* Check if the caller wanted to see the actual data */
if (lpBuffer)
{
memcpy(lpBuffer, Buffer->Data,
min(nBufferSize, Iosb.Information - sizeof(FILE_PIPE_PEEK_BUFFER)));
/* Give him what he wants */
RtlCopyMemory(lpBuffer,
Buffer->Data,
Iosb.Information -
FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]));
}
RtlFreeHeap(RtlGetProcessHeap(),
0,
Buffer);
return(TRUE);
/* Free the buffer and return success */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return TRUE;
}
/*
* @implemented
*/