|
From: CVS C. to T. <the...@li...> - 2011-11-09 23:43:37
|
Revision: 669
http://themis.svn.sourceforge.net/themis/?rev=669&view=rev
Author: mark_hellegers
Date: 2011-11-09 23:43:31 +0000 (Wed, 09 Nov 2011)
Log Message:
-----------
- Added an extra lock in NotifyDisconnect as it was accessing member variables.
- Only called timeout and disconnect when no other actions have been taken. Some other calls can end up calling Disconnect before the timeout check. Follow connection->owner->DataIsWaiting(connection) for an example.
Modified Paths:
--------------
trunk/themis/framework/connection.cpp
trunk/themis/framework/tcpmanager.cpp
Modified: trunk/themis/framework/connection.cpp
===================================================================
--- trunk/themis/framework/connection.cpp 2011-11-09 19:09:27 UTC (rev 668)
+++ trunk/themis/framework/connection.cpp 2011-11-09 23:43:31 UTC (rev 669)
@@ -133,8 +133,8 @@
return notified;
}
void Connection::NotifyDisconnect() {
-// BAutolock alock(lock);
-// if (alock.IsLocked()) {
+ BAutolock alock(lock);
+ if (alock.IsLocked()) {
if (owner!=NULL) {
if (notified_disconnect==0)
{
@@ -144,7 +144,7 @@
atomic_add(¬ified_disconnect,1);
}
}
-// }
+ }
}
Modified: trunk/themis/framework/tcpmanager.cpp
===================================================================
--- trunk/themis/framework/tcpmanager.cpp 2011-11-09 19:09:27 UTC (rev 668)
+++ trunk/themis/framework/tcpmanager.cpp 2011-11-09 23:43:31 UTC (rev 669)
@@ -122,7 +122,7 @@
int32 TCPManager::_Manager_Thread() {
// set_alarm(25000,B_PERIODIC_ALARM);
Connection *connection;
- int32 connect_count;
+ int32 connect_count = 0;
int32 current_time;
// int32 last_used;
@@ -131,14 +131,14 @@
while(!_quitter_) {
// if (acquire_sem(process_sem_1)==B_OK) {
// printf("processing\n");
- connect_count=Connection::CountConnections();
-
- if (connect_count>0) {
- current_time=real_time_clock();
- for (int32 i=0; i<connect_count; i++) {
+ if (lock.LockWithTimeout(25000)==B_OK)
+ {
+ connect_count=Connection::CountConnections();
+
+ if (connect_count>0) {
+ current_time=real_time_clock();
+ for (int32 i=0; i<connect_count; i++) {
- if (lock.LockWithTimeout(25000)==B_OK)
- {
// printf("TCP Manager: lock acquired\n");
connection=Connection::ConnectionAt(i);
if (connection != NULL && Connection::HasConnection(connection)) {
@@ -155,6 +155,12 @@
connection->owner->DataIsWaiting(connection);
}
}
+ else 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->IsDataWaiting()) {
@@ -163,13 +169,13 @@
connection->RetrieveData();
connection->lastusedtime=lastused;
}
+ else if ((connection->LastUsed()!=0) && ((current_time-connection->LastUsed())>=time_out)) {
+ // if (connection->owner!=NULL)
+ // connection->owner->DestroyingConnectionObject(connection);
+ connection->TimeOut();
+ Disconnect(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();
@@ -185,13 +191,16 @@
}
}
}
- lock.Unlock();
}
// snooze(10000);
}
-
+ lock.Unlock();
}
else {
+ connect_count = 0;
+ }
+
+ if (connect_count == 0) {
// No connections, so take it easy before we check again for connections.
// Otherwise we create a busy loop.
snooze(25000);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|