Date: Monday, January 29, 2007 @ 17:24:26
Author: marc
Path: /cvsroot/carob/carob
Modified: include/Connection.hpp (1.82 -> 1.83) src/Connection.cpp (1.106
-> 1.107)
Fixed corruptedConnectionClose(). Redundant boolean field isClosed
disappears since driverSocketPtr = NULL is enough. Splitted
clean-up into Connection::close() and system socket closing into
closeSocket(). CAROB-110
------------------------+
include/Connection.hpp | 7 ++--
src/Connection.cpp | 67 ++++++++++++++++++++++++++++++-----------------
2 files changed, 46 insertions(+), 28 deletions(-)
Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.82 carob/include/Connection.hpp:1.83
--- carob/include/Connection.hpp:1.82 Mon Jan 15 11:59:25 2007
+++ carob/include/Connection.hpp Mon Jan 29 17:24:25 2007
@@ -471,7 +471,7 @@
* but does not throw any exception.
* @return true if the connection has been closed without errors
*/
- bool closeSocket();
+ void closeSocket();
/**
* Serializes a write request on the output stream by sending only the needed
* parameters to reconstruct it on the controller
@@ -496,10 +496,9 @@
const DriverSocket& getDriverSocket() { return *driverSocketPtr; }
private:
- /** This connection socket pointer */
+ /** This connection socket pointer. NULL if the connection is closed
+ (or not yet opened) */
DriverSocket* driverSocketPtr;
- /** true if the connection is closed (or not opened...) */
- bool isClosed;
/** Commit mode of the connection (<code>true</code>= automatic). */
bool autoCommit;
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.106 carob/src/Connection.cpp:1.107
--- carob/src/Connection.cpp:1.106 Mon Jan 29 16:00:49 2007
+++ carob/src/Connection.cpp Mon Jan 29 17:24:25 2007
@@ -84,7 +84,6 @@
throw (AuthenticationException, NoMoreControllerException,
VirtualDatabaseUnavailableException, UnexpectedException) :
driverSocketPtr(NULL),
- isClosed(true),
autoCommit(true),
readOnly(false),
writeExecutedInTransaction(false),
@@ -168,7 +167,6 @@
try
{
connectToNextController();
- isClosed = false;
return;
}
catch (VirtualDatabaseUnavailableException vdbue)
@@ -305,15 +303,16 @@
// Brutally close network socket FIRST
try {
- driverSocketPtr->closeSocket();
+ this->closeSocket();
} catch (const SocketIOException& sioe) {
std::wostringstream buffer;
buffer << L"failed to force ->closeSocket(), probably already closed? " <<
sioe.description();
logError(fctName, buffer.str());
}
- // Then call the regular close(). It will try to send the close
- // command, and fail. We will survive anyway.
+ // Then call the regular close() to clean-up objects. It will
+ // notice that the socket is already closed and refrain to send the
+ // Close command to the controller.
close();
}
@@ -322,12 +321,14 @@
{
const wchar_t fctName[] = L"Connection::close";
+ if (isDebugEnabled())
+ logDebug(fctName, L"Cleaning connection to controller " +
static_cast<wstring>(connected_controller));
+
//Wait until other methods/Commands are done
LockScope ls(&connectionCS);
- isClosed = true;
-
- // delete all statements created by this connection unless told not to
+ // Clean-up: delete all statements created by this connection unless
+ // told not to
if (auto_delete_statements)
{
if (isDebugEnabled())
@@ -340,24 +341,20 @@
}
created_statements.clear();
}
- return closeSocket();
-}
-
-bool Connection::closeSocket()
-{
- const wchar_t fctName[] = L"Connection::closeSocket";
- bool closeOK = false;
if (driverSocketPtr == NULL)
{
- return true;
+ if (isInfoEnabled())
+ logInfo(fctName, L"driverSocketPtr was NULL (already closed)");
+ return false;
}
- if (isDebugEnabled())
- logDebug(fctName, L"Closing socket to controller " +
static_cast<wstring>(connected_controller));
+ bool closeOK = false;
try
{
// Try to cleanly close the connection (also on controller side)
+ if (isDebugEnabled())
+ logDebug(fctName, L"Sending Close command to controller " +
static_cast<wstring>(connected_controller));
sendCommand(*driverSocketPtr, Close);
closeOK = receiveBoolOrException();
}
@@ -366,13 +363,37 @@
if (isInfoEnabled())
logInfo(fctName, L"Could not inform controller we are closing
connection");
}
- // socket closing will be done in destructor
- delete driverSocketPtr;
- driverSocketPtr = NULL;
+ // actual system socket closing
+ closeSocket();
return closeOK;
}
+void Connection::closeSocket()
+{
+ const wchar_t fctName[] = L"Connection::closeSocket";
+
+ if (isDebugEnabled())
+ logDebug(fctName, L"Closing system socket to controller " +
static_cast<wstring>(connected_controller));
+
+ if (driverSocketPtr == NULL)
+ {
+ if (isInfoEnabled())
+ logInfo(fctName, L"... was NULL (already closed)");
+ return;
+ }
+
+ const DriverSocket *toDelete = driverSocketPtr;
+
+ // it's dying, so hide it from anyone else
+ driverSocketPtr = NULL;
+
+ // FIXME: should we unregister it?
+ // system socket closing is done in this destructor
+ delete toDelete;
+
+}
+
void Connection::setAutoCommit(bool autoCommitPrm)
throw (SocketIOException, BackendException, ControllerException,
ProtocolException, ConnectionException, UnexpectedException)
@@ -1043,7 +1064,7 @@
void Connection::throwExceptionIfClosed(const wstring& msg)
throw (DriverException, UnexpectedException)
{
- if (isClosed)
+ if (driverSocketPtr == NULL)
throw DriverException(msg);
}
@@ -1230,7 +1251,6 @@
if (isDebugEnabled())
logDebug(fctName, L"Closing socket of lost connection");
- isClosed = true;
closeSocket();
// inform controller pool of the failure: even if the info came from the
@@ -1247,7 +1267,6 @@
if (isDebugEnabled())
logDebug(fctName, L"Getting a new controller from the list...");
getConnectionToNewController();
- isClosed = false;
}
catch (AuthenticationException ae)
{
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits