-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwollinerecvw.cpp
More file actions
74 lines (60 loc) · 1.25 KB
/
Copy pathwollinerecvw.cpp
File metadata and controls
74 lines (60 loc) · 1.25 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#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::LineRecvW(HANDLE hFile, LPWSTR pBuf, DWORD dwBufSize,
DWORD dwTimeout)
{
if (dwBufSize < 2)
return 0;
bool bGood = true;
DWORD dwLen = 0;
for (LPWSTR ptr = pBuf; dwLen < dwBufSize - 2; )
{
if (!Read(hFile, ptr, sizeof WCHAR))
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 != sizeof WCHAR)
break;
if (ptr[0] == L'\r')
continue;
if (ptr[0] == L'\n')
break;
dwLen ++;
ptr ++;
}
if (bGood && (dwLen == 0))
SetLastError(ERROR_SUCCESS);
if (bGood)
{
pBuf[dwLen] = '\x00';
return dwLen;
}
if (GetLastError() == ERROR_HANDLE_EOF)
{
pBuf[dwLen] = '\x00';
return dwLen;
}
return 0;
}