NAME¶
Ns_ConnCopyToChannel, Ns_ConnCopyToDString, Ns_ConnCopyToFd, Ns_ConnCopyToFile -
Copy request content to open file or dstring
SYNOPSIS¶
#include "ns.h"
int
Ns_ConnCopyToChannel(conn, ncopy, chan)
int
Ns_ConnCopyToDString(conn, ncopy, dsPtr)
int
Ns_ConnCopyToFd(conn, ncopy, fd)
int
Ns_ConnCopyToFile(conn, ncopy, fp)
ARGUMENTS¶
- Ns_Channel chan (in)
- Pointer to Tcl channel open for write.
- Ns_Conn conn (in)
- Pointer to open connection.
- Ns_DString dsPtr (in)
- Initialized dstring.
- int fd (in)
- File descriptor open for write.
- FILE fp (in)
- Stdio FILE pointer open for write.
- int ncopy (in)
- Number of bytes to copy.
DESCRIPTION¶
These functions copy content from an open connection request to the given open
file descriptor, FILE, dstring, or Tcl_Channel. The routines work by copying
from the content buffer; see the man page on Ns_ConnContent for how
this buffer is managed for both small and large requests.
The functions all return the number of bytes copied which will
match the requested ncopy argument unless there is an error writing
the content or the requested bytes is greater than the number of bytes still
available to be read. An internal offset into the connection is maintained
and is shared with routines such as Ns_ConnRead which also consume
content from the same buffer. Note that routines which access the entire
content, e.g., Ns_ConnContent, Ns_ConnContentFd, or
Ns_ConnGetQuery will continue to provide access to the entire request
regardless if one of the Ns_ConnCopy or Ns_ConnRead functions
have been used.
EXAMPLES¶
The following example demonstrates copying user data to a temp file:
fd = open("myfile.out", O_WRONLY|O_BINARY);
len = Ns_ConnContentLength(conn);
if (Ns_ConnCopyToFd(conn, len, fd) != len) {
... error writing content or content already consumed ...
}
KEYWORDS¶
connection, content, read