stateblock NetworkSendBandwidthCounter augments RNetwork {
requires SystemTime;
addstate RNetwork.sendTimeSlice: int = 5000;
addstate RNetwork.sendByteLimit: int = 1000000;
addstate RNetwork.sendBytesLeft: int = 1000000;
addstate RNetwork.sendStartTime: long = 0;
// Timer reset.
helper updateSendTimer() {
if((RSystem.getCurrentTime() - sendStartTime) > sendTimeSlice) {
util.Message.debugMessage("Reset send bandwidth timer.");
sendStartTime = RSystem.getCurrentTime();
sendBytesLeft = sendByteLimit;
}
}
precode initialize () {
sendStartTime = RSystem.getCurrentTime ();
}
precode postSend (connection: RNetConnection, nbytes: int) {
sendBytesLeft -= nbytes;
}
precode preSend(connection: RNetConnection, nbytes: int) {
updateSendTimer();
}
}
Naccio Home Page
University of Virginia, Computer Science