-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwolbufrecv.cpp
More file actions
54 lines (44 loc) · 1 KB
/
Copy pathwolbufrecv.cpp
File metadata and controls
54 lines (44 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define WIN32_LEAN_AND_MEAN
#include <wio.h>
#ifdef _MSC_VER
#pragma comment(lib, "kernel32")
#endif
//-- wio.h definitions
//--------------- SafeSend(), LineRecv(), BufRecv() and BufSend() functions are
//--------------- used for I/O on overlapped streams such as sockets, comm
//--------------- devices or named pipes.
DWORD
WOverlapped::BufRecv(HANDLE hFile, PVOID pBuf, DWORD dwBufSize,
DWORD dwTimeout)
{
DWORD dwDone = 0;
bool bGood = true;
for (PVOID ptr = pBuf; dwDone < dwBufSize; )
{
if (!Read(hFile, ptr, dwBufSize - dwDone))
if (GetLastError() != ERROR_IO_PENDING)
{
bGood = false;
break;
}
else
if (!Wait(dwTimeout))
{
bGood = false;
break;
}
DWORD dwReadLen;
if (!GetResult(hFile, &dwReadLen))
{
bGood = false;
break;
}
if (dwReadLen == 0)
break;
dwDone += dwReadLen;
(*(LPBYTE*) &ptr) += dwReadLen;
}
if (bGood & (dwDone != dwBufSize))
SetLastError(ERROR_HANDLE_EOF);
return dwDone;
}