Networking Tools: Thread-hot Internet Classes (int library)
#include <rw/toolpro/coupler.h> RWStreamCoupler couple;
thr, net, int, tls (and possibly std)
RWStreamCoupler provides an automated mechanism for connecting an input stream to an output stream. It can be used in conjunction with the network communication portal streams and the thread-hot internet class library 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. Or it may simply be used 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 provided to terminate the processing of the input stream prior to the end of the stream.
#include <iostream.h> #include <fstream.h> #include <rw/toolpro/winsock.h> #include <rw/toolpro/url.h> #include <rw/toolpro/ftpa.h> #include <rw/toolpro/coupler.h> RWURL url1("file:///couple.exe"); RWURL url2("ftp://user:password@host/pub"); void main() { RWWinSockInfo info; try { // construct a coupler object, using binary mode // to couple RWStreamCoupler couple(RWStreamCoupler::BINARY); RWIFtpAgent putAgent( url2.host(), url2.user(), url2.password()); // construct an input stream ifstream istr(url1.path(), ios::in|ios::binary); RWSocketPortal p = putAgent.put( url2.path(), RWIFtpAgent::PASSIVE, RWIFtpAgent::BINARY); // construct an output stream RWPortalOStream ostr(p); // connect the input stream to the output stream couple(istr, ostr); // terminate the data connection RWBoolean closed = putAgent.dataClose(); } catch(const RWxmsg& msg) { cerr << "Error: " << msg.why() << endl; } }
typedef RWBoolean(*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 pre-Tools.h++ Professional enum values (ASCII, BINARY) have been retained, but are deprecated. You can keep the compiler from seeing the old values by defining RW_AVOID_PREPROCESSOR_PROBLEMS.
RWStreamCoupler(TransferMode mode=ASCII);
Constructs an RWStreamCoupler object. If the mode argument is not explicitly set, it is ASCII by default.
void setMode(TransferMode mode);
Sets the internal transfer mode to the passed-in mode.
RWBoolean operator()(istream& in, ostream& out); RWBoolean operator()(istream& in, ostream& out, Filter filter); RWBoolean operator()(istream& in, RWPortalOStream& out); RWBoolean 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.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.