From 4eefaf421bfeddf040d96a3dafb12e09673423d7 Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Sun, 31 Jan 2010 08:32:52 +0100 Subject: Imported Upstream version 1.3.1 --- db/client.cpp | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 db/client.cpp (limited to 'db/client.cpp') diff --git a/db/client.cpp b/db/client.cpp new file mode 100644 index 0000000..68a0c9e --- /dev/null +++ b/db/client.cpp @@ -0,0 +1,99 @@ +// client.cpp + +/** +* Copyright (C) 2009 10gen Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +*/ + +/* Client represents a connection to the database (the server-side) and corresponds + to an open socket (or logical connection if pooling on sockets) from a client. +*/ + +#include "stdafx.h" +#include "db.h" +#include "client.h" +#include "curop.h" +#include "json.h" + +namespace mongo { + + boost::mutex Client::clientsMutex; + set Client::clients; // always be in clientsMutex when manipulating this + boost::thread_specific_ptr currentClient; + + Client::Client(const char *desc) : + _curOp(new CurOp()), + _database(0), _ns("")/*, _nsstr("")*/ + ,_shutdown(false), + _desc(desc), + _god(0) + { + ai = new AuthenticationInfo(); + boostlock bl(clientsMutex); + clients.insert(this); + } + + Client::~Client() { + delete _curOp; + delete ai; + ai = 0; + _god = 0; + if ( !_shutdown ) { + cout << "ERROR: Client::shutdown not called!" << endl; + } + } + + bool Client::shutdown(){ + _shutdown = true; + + { + boostlock bl(clientsMutex); + clients.erase(this); + } + + bool didAnything = false; + + if ( _tempCollections.size() ){ + didAnything = true; + for ( list::iterator i = _tempCollections.begin(); i!=_tempCollections.end(); i++ ){ + string ns = *i; + dblock l; + setClient( ns.c_str() ); + if ( ! nsdetails( ns.c_str() ) ) + continue; + try { + string err; + BSONObjBuilder b; + dropCollection( ns , err , b ); + } + catch ( ... ){ + log() << "error dropping temp collection: " << ns << endl; + } + } + _tempCollections.clear(); + } + + return didAnything; + } + + BSONObj CurOp::_tooBig = fromjson("{\"$msg\":\"query not recording (too large)\"}"); + WrappingInt CurOp::_nextOpNum; + + Client::Context::Context( string ns , Database * db ) + : _client( currentClient.get() ) { + assert( db && db->isOk() ); + _client->setns( ns.c_str() , db ); + } + +} -- cgit v1.2.3