| |
| INT Peek( |
| |
LPBYTE lpBuffer, |
|
| |
INT cbBuffer |
|
| ); |
The Peek method reads the specified number of bytes from
the socket and copies them into the buffer, but it does not remove
the data from the internal socket buffer. The data may be of any
type, and is not terminated with a null character.
Parameters
- lpBuffer
- Pointer to the buffer in which the data will be stored. This
argument may be NULL, in which case no data is copied from the
socket buffers, however the function will return the number of bytes
available to read.
- cbBuffer
- The maximum number of bytes to read and copy into the specified
buffer. If the lpBuffer parameter is not NULL, this value
must be greater than zero.
Return Value
If the function succeeds, the return value is the number of bytes
available to read from the socket. A return value of zero indicates
that there is no data available to read at that time. If the function
fails, the return value is INET_ERROR. To get extended error
information, call GetLastError.
Remarks
The Peek method returns data that is available to read from
the socket, up to the number of bytes specified. The data returned by
this method is not removed from the socket buffers. It must be
consumed by a subsequent call to the Read method. The return
value indicates the number of bytes that can be read in a single
operation, up to the specified buffer size. However, it is important
to note that it may not indicate the total amount of data available
to be read from the socket at that time.
If no data is available to be read, the method will return a value
of zero. Using this method in a loop to poll a non-blocking socket
may cause the application to become non-responsive. To determine if
there is data available to be read, use the IsReadable method.
Requirements
Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header: Include cswsock10.h
Import Library: cswskv10.lib
See Also
EnableEvents,
IsBlocking,
IsReadable,
IsWritable, Read,
ReadLine,
RegisterEvent,
Write, WriteLine
|
|