SourcePro® API Reference Guide

 
List of all members | Public Member Functions
RWTimedPortal Class Reference

Provides timed send() and recv() calls. More...

#include <rw/network/RWTimedPortal.h>

Inheritance diagram for RWTimedPortal:
RWPortal

Public Member Functions

 RWTimedPortal ()
 
 RWTimedPortal (const RWPortal &portal, unsigned long timeout)
 
- Public Member Functions inherited from RWPortal
 RWPortal ()
 
 RWPortal (const RWPortal &x)
 
 ~RWPortal ()
 
RWPortaloperator= (const RWPortal &x)
 
RWNetBuf recv () const
 
int recv (char *buf, int bufLen, RWNetBuf::State *state=0) const
 
RWNetBuf recvAtLeast (int n) const
 
int recvAtLeast (char *buf, int bufLen, int n, RWNetBuf::State *state=0) const
 
int send (const RWCString &s) const
 
int send (const char *buf, int buflen) const
 
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
 

Additional Inherited Members

- Protected Member Functions inherited from RWPortal
 RWPortal (RWPortalImp *impl)
 
const RWPortalImpimplementation () const
 
RWPortalImpimplementation ()
 

Detailed Description

RWTimedPortal inherits from RWPortal to provide timed send() and recv() calls. If send() and recv() calls on the underlying RWPortal might block for too long, RWTimedPortal provides a mechanism for breaking out of those calls after a predetermined amount of time.

If the underlying RWPortal does not support timed send() and recv() calls, an RWNetTimeoutNotImplementedError exception is thrown the first time either send() or recv() is invoked.

If the specified timeout is exceeded in a call to send() or recv(), an RWNetOperationTimeoutError exception is thrown.

Example
#include <rw/network/RWInetAddr.h>
#include <rw/network/RWTimedPortal.h>
#include <rw/network/RWSocketPortal.h>
int
main()
{
try {
// make an address for echo port on localhost
RWInetAddr address(7, RWInetHost::me());
// make up some garbage data to send/recv
RWCString outgoing("Hello World");
RWCString incoming;
// construct a socket-based portal to echo port
RWSocketPortal portal(address);
// create a timed portal on portal with a 100 ms timeout
RWTimedPortal timed(portal, 100);
// do an untimed send using original portal
portal.send(outgoing);
// do a timed recv using timed portal
incoming = timed.recv();
}
catch(const RWxmsg& msg) {
cerr << "Error: " << msg.why() << endl;
}
return 0;
}

Constructor & Destructor Documentation

RWTimedPortal::RWTimedPortal ( )

Constructs an invalid RWTimedPortal. Attempts to send or receive on the portal throw an RWNetNoChannelError exception.

RWTimedPortal::RWTimedPortal ( const RWPortal portal,
unsigned long  timeout 
)

Constructs an RWTimedPortal from a portal object and a timeout. The RWTimedPortal object uses the underlying implementation from portal as the data sink for calls to send() and as the data source for calls to recv(). Passes the timeout parameter on every send and recv operation to that implementation.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.