0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/db/client.h

85 lines
2.3 KiB
C
Raw Normal View History

// client.h
/**
* Copyright (C) 2008 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 <http://www.gnu.org/licenses/>.
*/
/* 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.
todo: switch to asio...this will fit nicely with that.
*/
#pragma once
#include "lasterror.h"
namespace mongo {
2009-10-13 22:01:02 +02:00
class AuthenticationInfo;
class Database;
class Client {
Database* _database;
2009-10-13 22:01:02 +02:00
Namespace _ns;
//NamespaceString _nsstr;
list<string> _tempCollections;
public:
AuthenticationInfo *ai;
Database* database() { return _database; }
2009-10-13 22:01:02 +02:00
const char *ns() { return _ns.buf; }
void setns(const char *ns, Database *db) {
_database = db;
2009-10-13 22:01:02 +02:00
_ns = ns;
//_nsstr = ns;
2009-10-13 22:01:02 +02:00
}
void clearns() { setns("", 0); }
2009-10-13 22:01:02 +02:00
Client();
~Client();
void addTempCollection( const string& ns ){
_tempCollections.push_back( ns );
}
2009-10-13 22:01:02 +02:00
/* each thread which does db operations has a Client object in TLS.
call this when your thread starts.
*/
static void initThread();
/*
this has to be called as the client goes away, but before thread termination
@return true if anything was done
*/
bool shutdown();
};
2009-10-13 22:01:02 +02:00
/* defined in security.cpp */
extern boost::thread_specific_ptr<Client> currentClient;
2009-10-13 22:01:02 +02:00
inline Client& cc() {
return *currentClient.get();
}
inline void Client::initThread() {
assert( currentClient.get() == 0 );
currentClient.reset( new Client() );
}
};
2009-10-13 22:01:02 +02:00