oasys::RateLimitedSocket Class Reference

#include <RateLimitedSocket.h>

Inheritance diagram for oasys::RateLimitedSocket:

oasys::Logger List of all members.

Detailed Description

The RateLimitedSocket class contains a socket class and a token bucket and provides an interface to send data only if there is enough space to send it out in.

Note that the rate is configured in bits per second.

Definition at line 36 of file RateLimitedSocket.h.

Public Member Functions

 RateLimitedSocket (const char *logpath, u_int32_t rate, IPSocket *socket=NULL)
 Constructor.
int send (const char *bp, size_t len, int flags)
 Send the given data on the socket iff the rate controller indicates that there is space.
int sendto (char *bp, size_t len, int flags, in_addr_t addr, u_int16_t port)
 Send the given data on the socket iff the rate controller indicates that there is space.
TokenBucketbucket ()
 Accessors.
IPSocketsocket ()
 Accessors.
void set_socket (IPSocket *sock)
 Setters.

Protected Attributes

TokenBucket bucket_
IPSocketsocket_


Constructor & Destructor Documentation

oasys::RateLimitedSocket::RateLimitedSocket ( const char *  logpath,
u_int32_t  rate,
IPSocket socket = NULL 
)

Constructor.

Definition at line 23 of file RateLimitedSocket.cc.


Member Function Documentation

int oasys::RateLimitedSocket::send ( const char *  bp,
size_t  len,
int  flags 
)

Send the given data on the socket iff the rate controller indicates that there is space.

Returns:
IORATELIMIT if there isn't space in the token bucket for the given number of bytes, the return from IPSocket::send if there is space.

Definition at line 34 of file RateLimitedSocket.cc.

References ASSERT, bucket_, oasys::TokenBucket::drain(), oasys::IORATELIMIT, log_debug, oasys::TokenBucket::rate(), oasys::IPSocket::send(), socket_, and oasys::TokenBucket::tokens().

int oasys::RateLimitedSocket::sendto ( char *  bp,
size_t  len,
int  flags,
in_addr_t  addr,
u_int16_t  port 
)

Send the given data on the socket iff the rate controller indicates that there is space.

Returns:
IORATELIMIT if there isn't space in the token bucket for the given number of bytes, the return from IPSocket::sendto if there is space.

Definition at line 55 of file RateLimitedSocket.cc.

References ASSERT, bucket_, oasys::TokenBucket::drain(), oasys::IORATELIMIT, log_debug, oasys::TokenBucket::rate(), oasys::IPSocket::sendto(), socket_, and oasys::TokenBucket::tokens().

TokenBucket* oasys::RateLimitedSocket::bucket (  )  [inline]

Accessors.

Definition at line 68 of file RateLimitedSocket.h.

References bucket_.

Referenced by dtn::UDPConvergenceLayer::Sender::init().

IPSocket* oasys::RateLimitedSocket::socket (  )  [inline]

Accessors.

Definition at line 69 of file RateLimitedSocket.h.

References socket_.

void oasys::RateLimitedSocket::set_socket ( IPSocket sock  )  [inline]

Setters.

Definition at line 73 of file RateLimitedSocket.h.

References socket_.


Member Data Documentation

TokenBucket oasys::RateLimitedSocket::bucket_ [protected]

Definition at line 77 of file RateLimitedSocket.h.

Referenced by bucket(), send(), and sendto().

IPSocket* oasys::RateLimitedSocket::socket_ [protected]

Definition at line 78 of file RateLimitedSocket.h.

Referenced by send(), sendto(), set_socket(), and socket().


The documentation for this class was generated from the following files:
Generated on Thu Jun 7 16:57:00 2007 for DTN Reference Implementation by  doxygen 1.5.1