|
BOOL WriteStream( |
|
SOCKET hSocket, |
|
|
LPVOID lpvBuffer, |
|
|
LPDWORD lpdwLength, |
|
|
DWORD dwOptions |
|
); |
BOOL WriteStream( |
|
LPVOID lpvBuffer, |
|
|
LPDWORD lpdwLength, |
|
|
DWORD dwOptions |
|
); |
Write a stream of data to the client.
Parameters
- hSocket
- An optional parameter that specifies the handle to the client socket.
If this parameter is omitted, the socket handle for the active
client session will be used. If this method is called outside of a
server event handler, the socket handle must be specified.
- lpvBuffer
- Pointer to the buffer that contains or references the data to
be written to the socket. The actual argument depends on the value
of the dwOptions parameter which specifies how the data
stream will be accessed.
- lpdwLength
- A pointer to an unsigned integer value which specifies the size
of the buffer and contains the number of bytes written when the
method returns. This argument should should always point to an
initialized value. If the lpvBuffer argument specifies a
memory buffer or global memory handle, then this argument cannot
point to an initialized value of zero.
- dwOptions
- An unsigned integer value which specifies the stream buffer
type to be used when writing the data stream to the socket. One of
the following stream types may be specified:
Constant |
Description |
INET_STREAM_DEFAULT |
The default stream buffer type is determined by the value
passed as the lpvBuffer parameter. If the argument
specifies a a global memory handle, then the method will
write the data referenced by that handle; otherwise, the
method will consider the parameter a pointer to a block of
memory which contains data to be written. In most cases, it
is recommended that an application explicitly specify the
stream buffer type rather than using the default value. |
INET_STREAM_MEMORY |
The lpvBuffer argument specifies a pointer to a
block of memory which contains the data to be written to the
socket. If this stream buffer type is used, the
lpdwLength argument must point to an unsigned integer
which has been initialized with the size of the buffer. |
INET_STREAM_HGLOBAL |
The lpvBuffer argument specifies a global memory
handle that references the data to be written to the socket.
The handle must have been created by a call to the
GlobalAlloc or GlobalReAlloc function. If this stream buffer
type is used, the lpdwLength argument must point to an
unsigned integer which has been initialized with the size of
the buffer. |
INET_STREAM_HANDLE |
The lpvBuffer argument specifies a Windows handle
to an open file, console or pipe. This should be the same
handle value returned by the CreateFile function in the
Windows API. The data read using the ReadFile function with
this handle will be written to the socket. |
INET_STREAM_SOCKET |
The lpvBuffer argument specifies a socket handle.
The data read from the socket specified by this handle will
be written to the socket specified by the hSocket
parameter. The socket handle passed to this method must have
been created by this library; if it is a socket created by an
third-party library or directly by the Windows Sockets API,
you should either create another instance of the class and
attach the socket using the AttachHandle method or use the
INET_STREAM_HANDLE stream buffer type instead. |
Return Value
If the method succeeds, the return value is non-zero. If the
method fails, the return value is zero. To get extended error
information, call InetGetLastError.
Remarks
The WriteStream method enables an application to write an
arbitrarily large stream of data from memory or a file to the
specified socket. Unlike the Write method, which may not
write all of the data in a single method call, WriteStream
will only return when all of the data has been written or an error
occurs. This method will force the thread to block until the
operation completes.
It is possible for some data to have been written even if the
method returns a value of zero. Applications should also check the
value of the lpdwLength argument to determine if any data
was sent. For example, if a timeout occurs while the method is
waiting to write more data, it will return zero; however, some data
may have already been written to the socket prior to the error
condition.
Example
CFile *pFile = new CFile();
DWORD dwLength = 0;
if (!pFile->Open(strFileName, CFile::modeRead | CFile::shareDenyWrite))
return;
dwLength = pFile->GetLength();
if (dwLength > 0)
{
BOOL bResult = pServer->WriteStream(
pFile->m_hFile,
&dwLength,
INET_STREAM_HANDLE);
}
delete pFile;
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
Read,
ReadLine,
ReadStream,
StoreStream,
Write,
WriteLine
|
|