RateLimitedSocket.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _OASYS_RATE_LIMITED_SOCKET_H_
00018 #define _OASYS_RATE_LIMITED_SOCKET_H_
00019 
00020 // XXX/demmer for now this only works for IPSocket, but once Bowei
00021 // finishes the IO porting, there will be a new base class that this
00022 // class should use
00023 #include "IPSocket.h"
00024 #include "../debug/Log.h"
00025 #include "../util/TokenBucket.h"
00026 
00027 namespace oasys {
00028 
00036 class RateLimitedSocket : public Logger {
00037 public:
00041     RateLimitedSocket(const char* logpath,
00042                       u_int32_t rate,
00043                       IPSocket* socket = NULL);
00044 
00053     int send(const char* bp, size_t len, int flags);
00054 
00063     int sendto(char* bp, size_t len, int flags,
00064                in_addr_t addr, u_int16_t port);
00065     
00066     
00068     TokenBucket* bucket() { return &bucket_; }
00069     IPSocket*    socket() { return socket_; }
00071 
00073     void set_socket(IPSocket* sock) { socket_ = sock; }
00075     
00076 protected:
00077     TokenBucket bucket_;
00078     IPSocket*   socket_;
00079 };
00080 
00081 } // namespace oasys
00082 
00083 #endif /* _OASYS_RATE_LIMITED_SOCKET_H_ */

Generated on Thu Jun 7 16:56:51 2007 for DTN Reference Implementation by  doxygen 1.5.1