stateblock NetworkReceiveBandwidthCounter augments RNetwork {
requires SystemTime;
addstate RNetwork.receiveTimeSlice: int = 0;
addstate RNetwork.receiveByteLimit: int = 1000000;
addstate RNetwork.receiveBytesLeft: int = 1000000;
addstate RNetwork.receiveStartTime: long = 0;
// Timer reset.
helper updateReceiveTimer () {
if ((RSystem.getCurrentTime () - receiveStartTime) > receiveTimeSlice) {
debugMessage ("Reset receive bandwidth timer.");
receiveStartTime = RSystem.getCurrentTime ();
receiveBytesLeft = receiveByteLimit;
}
}
precode initialize () {
receiveStartTime = RSystem.getCurrentTime ();
}
precode postReceive (connection: RNetConnection, nbytes: int) {
receiveBytesLeft -= nbytes;
}
precode preReceive (connection: RNetConnection, nbytes: int) {
updateReceiveTimer ();
}
}
Naccio Home Page
University of Virginia, Computer Science