SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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
 
int recvAtLeast (char *buf, int bufLen, int n, RWNetBuf::State *state=0) const
 
RWNetBuf recvAtLeast (int n) const
 
int send (const char *buf, int buflen) const
 
int send (const RWCString &s) const
 
void sendAtLeast (const char *buf, int bufLen) const
 
int sendAtLeast (const char *buf, int bufLen, int n) const
 
void sendAtLeast (const RWCString &s) const
 
int sendAtLeast (const RWCString &s, int n) const
 

Additional Inherited Members

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

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/RWSocketPortal.h>
#include <rw/network/RWTimedPortal.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;
}
Offers powerful and convenient facilities for manipulating strings.
Definition stdcstring.h:826
Encapsulates a complete Internet address that includes type information, a host, and a port.
Definition RWInetAddr.h:68
static RWInetHost me()
Socket implementation of a portal.
Definition RWSocketPortal.h:34
Provides timed send() and recv() calls.
Definition RWTimedPortal.h:70
Initializes the Winsock DLL on Windows platforms.
Definition RWWinSockInfo.h:49
Base class for the hierarchy of exceptions in the Essential Tools Module.
Definition rwerr.h:57
virtual const char * why() const

Constructor & Destructor Documentation

◆ RWTimedPortal() [1/2]

RWTimedPortal::RWTimedPortal ( )

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

◆ RWTimedPortal() [2/2]

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 © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.