|
From: <ped...@us...> - 2010-01-07 01:17:09
|
Revision: 1431
http://cegcc.svn.sourceforge.net/cegcc/?rev=1431&view=rev
Author: pedroalves
Date: 2010-01-07 01:16:58 +0000 (Thu, 07 Jan 2010)
Log Message:
-----------
2010-01-07 Liu Yubao <yub...@ac...>
Implement PeekNamedPipe.
* PipeDev.cpp (MapCallerPtr): Declare.
(class PipeDeviceContext): Add new `peekBytes' method.
(IOControl): Handle PIPE_IOCTL_PEEK_NAMED_PIPE.
* PipeDev.h (PIPE_IOCTL_PEEK_NAMED_PIPE): Define.
(struct PeekStruct): New, moved from PipeLib.cpp.
* PipeLib.cpp (PeekNamedPipe): Don't #if 0. Adjust, fix typo and
and return TRUE on success.
* PipeLib.h (PeekNamedPipe): Declare.
Modified Paths:
--------------
trunk/cegcc/tools/PipeLib/ChangeLog
trunk/cegcc/tools/PipeLib/PipeDev.cpp
trunk/cegcc/tools/PipeLib/PipeDev.h
trunk/cegcc/tools/PipeLib/PipeLib.cpp
trunk/cegcc/tools/PipeLib/PipeLib.h
Modified: trunk/cegcc/tools/PipeLib/ChangeLog
===================================================================
--- trunk/cegcc/tools/PipeLib/ChangeLog 2010-01-02 06:04:04 UTC (rev 1430)
+++ trunk/cegcc/tools/PipeLib/ChangeLog 2010-01-07 01:16:58 UTC (rev 1431)
@@ -1,3 +1,16 @@
+2010-01-07 Liu Yubao <yub...@ac...>
+
+ Implement PeekNamedPipe.
+
+ * PipeDev.cpp (MapCallerPtr): Declare.
+ (class PipeDeviceContext): Add new `peekBytes' method.
+ (IOControl): Handle PIPE_IOCTL_PEEK_NAMED_PIPE.
+ * PipeDev.h (PIPE_IOCTL_PEEK_NAMED_PIPE): Define.
+ (struct PeekStruct): New, moved from PipeLib.cpp.
+ * PipeLib.cpp (PeekNamedPipe): Don't #if 0. Adjust, fix typo and
+ and return TRUE on success.
+ * PipeLib.h (PeekNamedPipe): Declare.
+
2009-12-12 Pedro Alves <ped...@us...>
* TestClient/Makefile (TARGET): Default to arm-mingw32ce.
Modified: trunk/cegcc/tools/PipeLib/PipeDev.cpp
===================================================================
--- trunk/cegcc/tools/PipeLib/PipeDev.cpp 2010-01-02 06:04:04 UTC (rev 1430)
+++ trunk/cegcc/tools/PipeLib/PipeDev.cpp 2010-01-07 01:16:58 UTC (rev 1431)
@@ -31,6 +31,8 @@
#include <set>
#include <string>
+extern "C" LPVOID MapCallerPtr(LPVOID ptr, DWORD dwLen);
+
#ifndef min
#define min(A, B) ((A) < (B) ? (A) : (B))
#endif
@@ -353,6 +355,14 @@
return fit;
}
+ DWORD peekBytes (BYTE* buf, DWORD bsize)
+ {
+ DWORD fit = min (bsize, size ());
+ for (DWORD i = 0; i < fit; i++)
+ buf[i] = buffer[(head + i) & (sizeof (buffer) - 1)];
+ return fit;
+ }
+
public:
DWORD OpenCount;
DWORD WROpenCount;
@@ -935,6 +945,57 @@
*pdwActualOut = (wcslen (dev->DeviceName) + 1) * sizeof (WCHAR);
bRet = TRUE;
break;
+ case PIPE_IOCTL_PEEK_NAMED_PIPE:
+ if (dwLenOut != sizeof (PeekStruct))
+ break; /* unknown version? */
+
+ PeekStruct* data = (PeekStruct *) pBufOut;
+ if (data->dwSize != sizeof (PeekStruct))
+ break; /* unknown version? */
+
+ *pdwActualOut = sizeof (PeekStruct);
+
+ DWORD actual = 0;
+ if (data->nBufferSize > 0 && data->lpBuffer != NULL)
+ {
+ LPVOID lpBuffer = MapCallerPtr (data->lpBuffer, data->nBufferSize);
+ if (NULL == lpBuffer)
+ break;
+
+ actual = dev->peekBytes ((BYTE *) lpBuffer, data->nBufferSize);
+
+ if (data->lpBytesRead != NULL)
+ {
+ LPDWORD lpBytesRead
+ = (LPDWORD) MapCallerPtr (data->lpBytesRead, sizeof (LPDWORD));
+ if (NULL == lpBytesRead)
+ break;
+ *lpBytesRead = actual;
+ }
+ }
+
+ if (data->lpTotalBytesAvail != NULL)
+ {
+ LPDWORD lpTotalBytesAvail
+ = (LPDWORD) MapCallerPtr (data->lpTotalBytesAvail,
+ sizeof (LPDWORD));
+ if (NULL == lpTotalBytesAvail)
+ break;
+ *lpTotalBytesAvail = dev->size ();
+ }
+
+ if (data->lpBytesLeftThisMessage != NULL)
+ {
+ LPDWORD lpBytesLeftThisMessage
+ = (LPDWORD) MapCallerPtr (data->lpBytesLeftThisMessage,
+ sizeof (LPDWORD));
+ if (NULL == lpBytesLeftThisMessage)
+ break;
+ *lpBytesLeftThisMessage = dev->size () - actual;
+ }
+
+ bRet = TRUE;
+ break;
}
return bRet;
Modified: trunk/cegcc/tools/PipeLib/PipeDev.h
===================================================================
--- trunk/cegcc/tools/PipeLib/PipeDev.h 2010-01-02 06:04:04 UTC (rev 1430)
+++ trunk/cegcc/tools/PipeLib/PipeDev.h 2010-01-07 01:16:58 UTC (rev 1431)
@@ -39,6 +39,19 @@
#define PIPE_IOCTL_SET_PIPE_TAG \
CTL_CODE(FILE_DEVICE_STREAMS, 2050, METHOD_BUFFERED, FILE_ANY_ACCESS)
+#define PIPE_IOCTL_PEEK_NAMED_PIPE \
+ CTL_CODE(FILE_DEVICE_STREAMS, 2051, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
#define DEVICE_DLL_NAME L"PipeDev.dll"
+struct PeekStruct
+{
+ DWORD dwSize; /* for future extension */
+ LPVOID lpBuffer;
+ DWORD nBufferSize;
+ LPDWORD lpBytesRead;
+ LPDWORD lpTotalBytesAvail;
+ LPDWORD lpBytesLeftThisMessage;
+};
+
#endif
Modified: trunk/cegcc/tools/PipeLib/PipeLib.cpp
===================================================================
--- trunk/cegcc/tools/PipeLib/PipeLib.cpp 2010-01-02 06:04:04 UTC (rev 1430)
+++ trunk/cegcc/tools/PipeLib/PipeLib.cpp 2010-01-07 01:16:58 UTC (rev 1431)
@@ -191,50 +191,33 @@
return TRUE;
}
-#if 0
-struct PeekStruct
-{
- DWORD Size; /* for future extension */
- PVOID lpBuffer,
- DWORD nBufferSize,
-
- /* TODO: We need to use MapPtr for this to work */
- LPDWORD lpBytesRead,
- LPDWORD lpTotalBytesAvail,
- LPDWORD lpBytesLeftThisMessage
- };
-
PIPELIB_API BOOL
PeekNamedPipe (HANDLE hNamedPipe,
LPVOID lpBuffer,
DWORD nBufferSize,
LPDWORD lpBytesRead,
LPDWORD lpTotalBytesAvail,
- LPDWORD lpBytesLeftThisMessage
- )
+ LPDWORD lpBytesLeftThisMessage)
{
- DWORD avail;
DWORD actual;
PeekStruct data;
- data.Size = sizeof (PeekStruct);
+ data.dwSize = sizeof (PeekStruct);
data.lpBuffer = lpBuffer;
data.nBufferSize = nBufferSize;
data.lpBytesRead = lpBytesRead;
data.lpTotalBytesAvail = lpTotalBytesAvail;
data.lpBytesLeftThisMessage = lpBytesLeftThisMessage;
- if (!DeviceIoControl (hNamedPipe, PIPE_IOCTRL_PEEK_NAMED_PIPE,
+ if (!DeviceIoControl (hNamedPipe, PIPE_IOCTL_PEEK_NAMED_PIPE,
NULL, 0,
- (LPVOID)&data, sizeof (PeekStruct), &actual, NULL))
+ (LPVOID) &data, sizeof (PeekStruct), &actual, NULL))
return FALSE;
- /* We can detect here if we are talking to an older driver. */
- if (actual != data.Size)
+ /* We can detect here if we are talking to an older driver. */
+ if (actual != data.dwSize)
return FALSE;
- return FALSE;
+ return TRUE;
}
-
-#endif
Modified: trunk/cegcc/tools/PipeLib/PipeLib.h
===================================================================
--- trunk/cegcc/tools/PipeLib/PipeLib.h 2010-01-02 06:04:04 UTC (rev 1430)
+++ trunk/cegcc/tools/PipeLib/PipeLib.h 2010-01-07 01:16:58 UTC (rev 1431)
@@ -34,10 +34,11 @@
#endif
PIPELIB_API BOOL CreatePipe (PHANDLE,PHANDLE,LPSECURITY_ATTRIBUTES,DWORD);
+PIPELIB_API BOOL PeekNamedPipe (HANDLE,LPVOID,DWORD,LPDWORD,LPDWORD,LPDWORD);
+
PIPELIB_API BOOL GetPipeName (HANDLE, WCHAR*);
/* Internal, for pipedev.dll debugging purposes. */
PIPELIB_API BOOL SetPipeTag (HANDLE, const WCHAR*);
-
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|