forked from qdaxb/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnectionmanager.cpp
More file actions
47 lines (42 loc) · 980 Bytes
/
connectionmanager.cpp
File metadata and controls
47 lines (42 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "connectionmanager.h"
#include "httpconnection.h"
#include <stdlib.h>
#include <map>
#include "slab.h"
#include "common.h"
using namespace std;
ConnectionManager *ConnectionManager::instance=0;
int ConnectionManager::size()
{
return conns->size();
}
HttpConnection* ConnectionManager::get(int key)
{
map<int,HttpConnection*>::iterator it=conns->find(key);
if(it==conns->end())
return create(key);
else
return it->second;
}
void ConnectionManager::release(int key)
{
map<int,HttpConnection*>::iterator it=conns->find(key);
if(it==conns->end())
return;
HttpConnection *conn=it->second;
Slab<HttpConnection>::dealloc(conn);
conns->erase(it);
}
HttpConnection* ConnectionManager::create(int key)
{
map<int,HttpConnection*>::iterator it=conns->find(key);
if(it!=conns->end())
{
it->second->reuse();
return it->second;
}
HttpConnection *conn=Slab<HttpConnection>::alloc();
conn->setServerContext(context);
(*conns)[key]=conn;
return conn;
}