-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwolbufsend.cpp
More file actions
40 lines (32 loc) · 870 Bytes
/
Copy pathwolbufsend.cpp
File metadata and controls
40 lines (32 loc) · 870 Bytes
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
#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.
BOOL
WOverlapped::BufSend(HANDLE hFile, const void *pBuf, DWORD dwBufSize,
DWORD dwTimeout)
{
DWORD dwDone = 0;
for (const void *ptr = pBuf; dwDone < dwBufSize; )
{
if (!Write(hFile, ptr, dwBufSize - dwDone))
if (GetLastError() != ERROR_IO_PENDING)
break;
else
if (!Wait(dwTimeout))
break;
DWORD dwWriteLen;
if (!GetResult(hFile, &dwWriteLen))
break;
if (dwWriteLen == 0)
break;
dwDone += dwWriteLen;
*(CONST BYTE**) &ptr += dwWriteLen;
}
return dwDone == dwBufSize;
}