Original Post
Hi.
I am implementing an overlapped I/O based Winsock program. I would like to know how to format the data buffer after WSARecv returns. For example:
-----
// Allocate 100 bytes.
TCHAR *data = new data[100 + 1];
data[100] = NULL;
// Link data buffer and size to WSABUF.
WSABUF wBuf;
wBuf.len = 10000;
wBuf.buf = data;
...
WSARecv(..., &wBuf,...,);
...
-----
Given WSARecv returns after sometime with the data, how do you format, 20 bytes of valid data. In other words, data could contain 100 bytes of data, however, what if only 20 bytes are valid and the rest are random data Winsock produces from the socket?
I tried using CString and trim(), but it does not seem to help under an overlapped I/O. For example:
-----
WSARecv(...);
...
CString validData = CString(data);
validData.trim();
-----
The solution above does not work for overlapped I/O. Even with trim(), validData will hold some valid data and a whole lot of random bytes.
I would like to know how to format a raw byte data buffer into valid characters only.
Thanks,
Kuphryn