|
From: CVS C. to T. <the...@li...> - 2011-11-09 19:09:34
|
Revision: 668
http://themis.svn.sourceforge.net/themis/?rev=668&view=rev
Author: mark_hellegers
Date: 2011-11-09 19:09:27 +0000 (Wed, 09 Nov 2011)
Log Message:
-----------
- Avoid the busy loop by snoozing when there are no connections.
- Small cleanup of the code.
Modified Paths:
--------------
trunk/themis/framework/tcpmanager.cpp
Modified: trunk/themis/framework/tcpmanager.cpp
===================================================================
--- trunk/themis/framework/tcpmanager.cpp 2011-10-08 19:59:17 UTC (rev 667)
+++ trunk/themis/framework/tcpmanager.cpp 2011-11-09 19:09:27 UTC (rev 668)
@@ -141,65 +141,48 @@
{
// printf("TCP Manager: lock acquired\n");
connection=Connection::ConnectionAt(i);
- if (connection == NULL || !Connection::HasConnection(connection))
- {
- lock.Unlock();
- //snooze(10000);
- continue;
- }
- if (connection->IsConnected())
- {
- if (connection->IsInUse())
- {
- if (!connection->NotifiedConnect())
- {
- if (!connection->already_connected)
- connection->ConnectionEstablished();
- connection->NotifyConnect();
- } else
- {
- if (connection->IsDataWaiting())
- {
- connection->RetrieveData();
- if (connection->owner!=NULL)
- {
- connection->owner->DataIsWaiting(connection);
+ if (connection != NULL && Connection::HasConnection(connection)) {
+ if (connection->IsConnected()) {
+ if (connection->IsInUse()) {
+ if (!connection->NotifiedConnect()) {
+ if (!connection->already_connected)
+ connection->ConnectionEstablished();
+ connection->NotifyConnect();
+ } else {
+ if (connection->IsDataWaiting()) {
+ connection->RetrieveData();
+ if (connection->owner!=NULL) {
+ connection->owner->DataIsWaiting(connection);
+ }
}
}
+ } else {
+ if (connection->IsDataWaiting()) {
+ // printf("TCP Manager: data is waiting on unused connection; receiving and flushing data\n");
+ int32 lastused=connection->LastUsed();
+ connection->RetrieveData();
+ connection->lastusedtime=lastused;
+ }
}
- } else
- {
- if (connection->IsDataWaiting())
- {
-// printf("TCP Manager: data is waiting on unused connection; receiving and flushing data\n");
- int32 lastused=connection->LastUsed();
- connection->RetrieveData();
- connection->lastusedtime=lastused;
- }
- }
- if ((connection->LastUsed()!=0) && ((current_time-connection->LastUsed())>=time_out))
- {
-// if (connection->owner!=NULL)
-// connection->owner->DestroyingConnectionObject(connection);
- connection->TimeOut();
- Disconnect(connection);
- }
- } else
- {
- if (!connection->NotifiedDisconnect())
- {
- connection->NotifyDisconnect();
-// Disconnect(connection);
- }
- else
- {
- if ((connection->LastUsed()!=0) && ((current_time-connection->LastUsed())>=time_out))
- {
-// if (connection->owner!=NULL)
-// connection->owner->DestroyingConnectionObject(connection);
+ if ((connection->LastUsed()!=0) && ((current_time-connection->LastUsed())>=time_out)) {
+ // if (connection->owner!=NULL)
+ // connection->owner->DestroyingConnectionObject(connection);
connection->TimeOut();
Disconnect(connection);
}
+ } else {
+ if (!connection->NotifiedDisconnect()) {
+ connection->NotifyDisconnect();
+ // Disconnect(connection);
+ }
+ else {
+ if ((connection->LastUsed()!=0) && ((current_time-connection->LastUsed())>=time_out)) {
+ // if (connection->owner!=NULL)
+ // connection->owner->DestroyingConnectionObject(connection);
+ connection->TimeOut();
+ Disconnect(connection);
+ }
+ }
}
}
lock.Unlock();
@@ -208,7 +191,11 @@
}
}
- //snooze(25000);
+ else {
+ // No connections, so take it easy before we check again for connections.
+ // Otherwise we create a busy loop.
+ snooze(25000);
+ }
// release_sem(process_sem_2);
// }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|