Module: Internet Protocols Module Package: Internet Basics
Does not inherit
#include <rw/internet/RWStreamCoupler.h>
RWStreamCoupler provides an automated mechanism for connecting an input stream to an output stream. You can use it in conjunction with the network portal streams and the Internet classes to couple an FTP get to an FTP put, an FTP get to a file, an FTP put from a file, and a POP3 get to a file. You can also use it to automate copying one file to another.
The coupling mechanism respects canonical line termination in ASCII mode, and always uses <cr><lf> pairs to terminate lines when streaming out to a portal.
An optional end-of-input filter may be added to terminate the processing of the input stream prior to the end of the stream.
#include <rw/rstream.h> #include <rw/network/RWWinSockInfo.h> #include <rw/network/RWSocketPortal.h> #include <rw/network/RWPortalIStream.h> #include <rw/network/RWInetHost.h> #include <rw/network/RWInetAddr.h> #include <rw/internet/RWStreamCoupler.h> int main(void) { RWWinSockInfo info; try { // get an address for daytime port on localhost RWInetAddr addr("daytime", RWInetHost::me()); // connect to address RWSocketPortal portal(addr); // construct an input stream RWPortalIStream istr(portal); // construct a coupler object using ascii mode to couple RWStreamCoupler couple; // connect the input stream to the output stream cout couple(istr, cout); } catch(const RWxmsg& msg) { cerr << "Error: " << msg.why() << endl; } return 0; }
typedef bool(*Filter)(const RWCString&);
Defines a Filter function that takes const RWCString& as its argument. The purpose of a possible customized Filter function is to allow the termination of the processing of an input stream prior to the end of the stream.
enum TransferMode { mode_ascii, mode_binary }
Enumerates whether an RWStreamCoupler object adopts a line mode (mode_ascii) transfer with possible line termination and filter issues, or a byte mode (mode_binary) transfer.
The former enum values (ASCII, BINARY) have been retained, but are deprecated. You can refuse support for these values by defining RW_AVOID_PREPROCESSOR_PROBLEMS.
RWStreamCoupler(TransferMode mode=mode_ascii);
Constructs an RWStreamCoupler object. If the mode argument is not explicitly set, it is ASCII by default.
bool operator()(istream& in, ostream& out); bool operator()(istream& in, ostream& out, Filter filter); bool operator()(istream& in, RWPortalOStream& out); bool operator()(istream& in, RWPortalOStream& out, Filter filter);
Streams the contents of in into out. If the out argument is an RWPortalOStream and the current transfer mode is ASCII, <cr><lf> line termination is enforced. If a filter function is passed in and the transfer mode is ASCII, each line of input from in is passed to the filter before streaming out to out.
TransferMode getMode(void) const;
Gets the current internal transfer mode.
void setMode(TransferMode mode);
Sets the internal transfer mode.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.