From 4e60ec0df1ef54a02bea0d5300e89e51efe7a58d Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Tue, 13 Jan 2009 12:53:00 -0500 Subject: [PATCH] sayPiggyBack/piggyBack not implemented yet, just passes through to say --- SConstruct | 1 + client/dbclient.cpp | 14 +++++++++++++- client/dbclient.h | 2 ++ db/instance.h | 4 ++++ grid/message.cpp | 4 ++++ grid/message.h | 2 ++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index 50e99665bb7..d06c1a26b24 100644 --- a/SConstruct +++ b/SConstruct @@ -130,6 +130,7 @@ env.Library( "mongoclient" , commonFiles + coreDbFiles ) # examples clientEnv.Program( "firstExample" , [ "client/examples/first.cpp" ] ) +clientEnv.Program( "secondExample" , [ "client/examples/second.cpp" ] ) # testing clientEnv.Program( "test" , Glob( "dbtests/*.cpp" ) ) diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 498c3ff01a2..5656e40e217 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -293,6 +293,10 @@ void DBClientConnection::say( Message &toSend ) { port().say( toSend ); } +void DBClientConnection::sayPiggyBack( Message &toSend ) { + port().piggyBack( toSend ); +} + bool DBClientConnection::call( Message &toSend, Message &response, bool assertOk ) { if ( !port().call(toSend, response) ) { failed = true; @@ -387,7 +391,15 @@ BSONObj DBClientCursor::next() { DBClientCursor::~DBClientCursor(){ if ( cursorId ){ - cerr << "TODO: need to kill the cursor here __FILE__:__LINE__" << endl; + BufBuilder b; + b.append( (int)0 ); // reserved + b.append( (int)1 ); // number + b.append( cursorId ); + + Message m; + m.setData( dbKillCursors , b.buf() , b.len() ); + + connector->sayPiggyBack( m ); } } diff --git a/client/dbclient.h b/client/dbclient.h index c412ed0cca8..42761c2992c 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -76,6 +76,7 @@ class DBConnector { public: virtual bool call( Message &toSend, Message &response, bool assertOk=true ) = 0; virtual void say( Message &toSend ) = 0; + virtual void sayPiggyBack( Message &toSend ) = 0; virtual void checkResponse( const char *data, int nReturned ) {} }; @@ -372,6 +373,7 @@ public: protected: virtual bool call( Message &toSend, Message &response, bool assertOk = true ); virtual void say( Message &toSend ); + virtual void sayPiggyBack( Message &toSend ); virtual void checkResponse( const char *data, int nReturned ); }; diff --git a/db/instance.h b/db/instance.h index e837cabe190..ce7e23d9d6d 100644 --- a/db/instance.h +++ b/db/instance.h @@ -94,4 +94,8 @@ class DBDirectClient : public DBClientBase { virtual string toString() { return "DBDirectClient"; } virtual bool call( Message &toSend, Message &response, bool assertOk=true ); virtual void say( Message &toSend ); + virtual void sayPiggyBack( Message &toSend ){ + // don't need to piggy back when connected locally + return say( toSend ); + } }; diff --git a/grid/message.cpp b/grid/message.cpp index 2035c3021cf..fb82ed157d3 100644 --- a/grid/message.cpp +++ b/grid/message.cpp @@ -287,3 +287,7 @@ void MessagingPort::say(Message& toSend, int responseTo) { log() << "MessagingPort say send() error " << errno << ' ' << farEnd.toString() << endl; } } + +void MessagingPort::piggyBack( Message& toSend ){ + say( toSend ); +} diff --git a/grid/message.h b/grid/message.h index 6be37e6b61a..9e947cfee07 100644 --- a/grid/message.h +++ b/grid/message.h @@ -60,6 +60,8 @@ public: void reply(Message& received, Message& response); bool call(Message& toSend, Message& response); void say(Message& toSend, int responseTo = -1); + + void piggyBack( Message& toSend ); private: int sock;