本文整理汇总了C++中TCPConnection::updateRemoteSpeed方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPConnection::updateRemoteSpeed方法的具体用法?C++ TCPConnection::updateRemoteSpeed怎么用?C++ TCPConnection::updateRemoteSpeed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPConnection
的用法示例。
在下文中一共展示了TCPConnection::updateRemoteSpeed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeBandwidth
/**
* Removes a connection from the bandwidth allocator
* Requests all other connections update their speed
*/
int BandwidthAllocator::removeBandwidth(TCPConnection* connection) {
boost::unique_lock<boost::mutex> lock(queueMutex);
// If we are not in a consistant state - wait
while(unsettled.size() > 0 || currentlyWorking) queueWaiting.wait(lock);
printf("1\n");
currentlyWorking = true;
int removeConnectionFd = connection->getSockFd();
int numConnections = settled.size();
int nodeSpeed = UPLINK_SPEED;
if (numConnections != 1) nodeSpeed = UPLINK_SPEED / (numConnections - 1);
printf("2\n");
TCPConnection* currentConnection;
for (int i = 0; i < numConnections; i++) {
currentConnection = settled.front();
settled.pop();
if (currentConnection->getSockFd() != removeConnectionFd) {
currentConnection->updateRemoteSpeed(nodeSpeed);
unsettled[currentConnection->getSockFd()] = currentConnection;
}
}
printf("3\n");
while(unsettled.size() > 0) queueWaiting.wait(lock);
printf("4\n");
currentlyWorking = false;
queueWaiting.notify_all();
printf("5\n");
return 0;
}
示例2: getBandwidth
/**
* Allocates some bandwidth for the new TCP connection
* Notifies all the other connections to change their speed
*/
int BandwidthAllocator::getBandwidth(TCPConnection* connection) {
boost::unique_lock<boost::mutex> lock(queueMutex);
while(unsettled.size() > 0 || currentlyWorking) queueWaiting.wait(lock);
int numConnections = settled.size();
int nodeSpeed = UPLINK_SPEED / (numConnections + 1);
TCPConnection* currentConnection;
for (int i = 0; i < numConnections; i++) {
currentConnection = settled.front();
settled.pop();
unsettled[currentConnection->getSockFd()] = currentConnection;
currentConnection->updateRemoteSpeed(nodeSpeed);
}
puts("Waiting for unsettled to sort itself out...");
while(unsettled.size() > 0) queueWaiting.wait(lock);
settled.push(connection);
currentlyWorking = false;
queueWaiting.notify_all();
// Return the speed we need to run at
// When we update this to handle flows at any time reverse so
// we send a bandwidth alloc to the receipent
return nodeSpeed;
}