Date: Friday, November 18, 2005 @ 17:58:53
Author: gilles
Path: /cvsroot/carob/carob
Modified: include/Connection.hpp (1.20 -> 1.21) src/Connection.cpp (1.23
-> 1.24)
Added protocol synchronization checkpoints (SEQUOIA-212) by centralizing
command sending in one static function 'sendCommand'
------------------------+
include/Connection.hpp | 18 +++++++++++++++++-
src/Connection.cpp | 29 +++++++++++++++++++++--------
2 files changed, 38 insertions(+), 9 deletions(-)
Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.20 carob/include/Connection.hpp:1.21
--- carob/include/Connection.hpp:1.20 Fri Nov 18 17:47:51 2005
+++ carob/include/Connection.hpp Fri Nov 18 17:58:53 2005
@@ -25,7 +25,12 @@
#include "CriticalSection.hpp"
#include "DriverSocket.hpp"
-#define ProtocolVersion 24
+/** "Controller Ready" magic number. */
+#define ControllerPrompt 0x1FA1501F
+/** Command prefix sent before each command */
+#define CommandPrefix 0xB015CA
+
+#define ProtocolVersion 26
//#define Ping -1
#define StatementExecuteQuery 0
@@ -98,6 +103,17 @@
public:
virtual ~Connection();
+ /**
+ * Before sending a command code, checks that the controller is
+ * synchronized/ready to accept it. Then sends it.
+ *
+ * @param socket on which to read and write
+ * @param command to send
+ * @throws IOException on socket error
+ * @throws DriverSQLException on protocol corruption
+ */
+ static void sendCommand(const DriverSocket& socket, int32_t command)
+ throw (SocketIOException, ProtocolException, UnexpectedException);
/**
* If a connection is in auto-commit mode, then all its SQL statements will
be
* executed and committed as individual transactions. Otherwise, its SQL
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.23 carob/src/Connection.cpp:1.24
--- carob/src/Connection.cpp:1.23 Fri Nov 18 17:47:51 2005
+++ carob/src/Connection.cpp Fri Nov 18 17:58:53 2005
@@ -58,6 +58,19 @@
}
}
+void Connection::sendCommand(const DriverSocket& socket, int32_t command)
+ throw (SocketIOException, ProtocolException, UnexpectedException)
+{
+ int32_t ack = -1;
+ socket>>ack;
+ if (ack != ControllerPrompt)
+ throw ProtocolException(
+ L"Protocol corruption while trying to send command: "
+ + toWString(command) + L". Check the previous command");
+ socket<<CommandPrefix;
+ socket<<command;
+}
+
bool Connection::initConnection(const ConnectionParameters& prms)
throw (ConnectionException, AuthenticationException, UnexpectedException)
{
@@ -221,7 +234,7 @@
if (isDebugEnabled())
logDebug(fctName, L"Closing connection");
- *driverSocketPtr<<Close;
+ sendCommand(*driverSocketPtr, Close);
isClosed = true;
bool closeOK;
@@ -289,7 +302,7 @@
//TODO: Should we try/catch ?
if (isDebugEnabled())
logDebug(fctName, L"Setting connection in autocommit mode");
- *driverSocketPtr<<SetAutoCommit;
+ sendCommand(*driverSocketPtr, SetAutoCommit);
bool ack = false;
ack = receiveBoolOrException();
writeExecutedInTransaction = false;
@@ -299,7 +312,7 @@
}
else
{
- *driverSocketPtr<<Begin;
+ sendCommand(*driverSocketPtr, Begin);
transactionId = receiveLongOrException();
autoCommit = false;
@@ -328,7 +341,7 @@
int64_t firstTransactionId = transactionId;
try
{
- *driverSocketPtr<<Commit;
+ sendCommand(*driverSocketPtr, Commit);
// Commit is followed by a BEGIN
transactionId = receiveLongOrException();
@@ -377,7 +390,7 @@
int64_t initialTransactionId = transactionId;
try
{
- *driverSocketPtr<<Rollback;
+ sendCommand(*driverSocketPtr, Rollback);
// Rollback is followed by a BEGIN
transactionId = receiveLongOrException();
writeExecutedInTransaction = false;
@@ -444,7 +457,7 @@
try
{
setConnectionParametersOnRequest(r);
- *driverSocketPtr<<StatementExecuteUpdate;
+ sendCommand(*driverSocketPtr, StatementExecuteUpdate);
writeRequestOnStream(r);
controllerResponse = receiveIntOrException();
}
@@ -494,7 +507,7 @@
try
{
setConnectionParametersOnRequest(sr);
- *driverSocketPtr<<StatementExecuteQuery;
+ sendCommand(*driverSocketPtr, StatementExecuteQuery);
sr.sendToStream(*driverSocketPtr, controllerNeedsSqlSkeleton);
if (isDebugEnabled())
@@ -535,7 +548,7 @@
checkIfConnected();
try
{
- *driverSocketPtr<<CloseRemoteResultSet;
+ sendCommand(*driverSocketPtr, CloseRemoteResultSet);
*driverSocketPtr<<cursorName;
if (isDebugEnabled())
logDebug(fctName, L"Closing remote ResultSet");
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits