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