Networking Tools: Network Communication Classes (net library)
#include <rw/toolpro/portal.h> RWPortal portal = RWSocketPortal(RWInetAddr(42, "tsunami.roguewave.com"));
net, tls (and possibly std)
An RWPortal is an access point of a reliable byte stream communication channel. It is possible for more than one RWPortal to access the same communications channel. This happens, for example, when using the copy constructor and assignment operator. Unless explicitly constructed otherwise, portal classes are designed so that when the last portal into a channel disappears, the communications channel is closed.
RWPortals are lightweight objects. Since copying and assignment copy only the RWPortal and not the underlying communications channel, these operations are inexpensive. As a result, RWPortals can be returned by value from functions and used as member data in objects.
RWPortals are implemented using the interface-implementation design pattern as described in the Tools.h++ Professional User's Guide. The RWPortal itself is really a handle to an implementation that represents the communication channel.
RWPortal(); RWPortal(const RWPortal&);
The default constructor creates a portal that cannot send or receive. Trying to send or receive throws an exception.
~RWPortal();
Destroys this portal. If there are other portals that were created from this one by assignment or copying, they are unaffected.
RWPortal(const RWPortal& x);
Creates a copy of x.
RWPortal& operator=(const RWPortal& x);
Makes self a portal to the same channel as x. Disconnects from the current channel, if any.
RWCString recv() const; int recv(char* buf, int bufLen) const
Receives a buffer of data. The version returning an int returns the number of characters actually received. recv() makes only one call to the communications channel.
RWCString recvAtLeast(int n) const; int recvAtLeast(char *buf, int bufLen, int n) const;
Receives at least n characters into the buffer. The second version returns the number of bytes actually received. The implementation loops over recv until either all the data is received or, for some reason, no data is returned. If no data is returned by recv, an exception is thrown. Calling recvAtLeast on a non-blocking channel is therefore likely to cause an exception.
int send(const RWCString& s) const; int send(const char* buf, int buflen) const;
Sends a buffer of data. Returns the number of bytes actually sent. send() makes only one call to the communications channel.
int sendAtLeast(const char* buf, int bufLen, int n) const; void sendAtLeast(const char* buf, int bufLen) const; int sendAtLeast(const RWCString& s, int n) const; void sendAtLeast(const RWCString& s) const;
Sends at least n characters into the communications channel. If n is omitted, all of the data is sent where appropriate, and the number of bytes actually sent is returned. The implementation loops over send to send the data. If any of the calls to send cannot send any data, an exception is thrown. Calling sendAtLeast on a non-blocking channel is therefore likely to cause an exception.
RWPortal(RWPortalImp *impl);
Specifies the portal implementation. This is used by derived classes that create specific types of portals by passing in specific types of portal implementations. The argument, like all RWPortalImps, must live on the heap.
RWBoolean operator==(const RWPortal&p, const RWPortal& q)
Returns TRUE if p and q both use the same underlying portal implementation object.
const RWPortalImp* implementation() const {return impl_;}
Derived classes may need to do things to the implementation. However, they are only allowed a const pointer to prevent them from trying to change what impl_ points to.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.