-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdslserverklr_handler.h
75 lines (62 loc) · 1.66 KB
/
dslserverklr_handler.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef __DSLSERVERKLR_HANDLER_H_
#define __DSLSERVERKLR_HANDLER_H_
/// application
#include "common.h"
class dslhandler : public bdatahandler
{
public :
dslhandler() {};
dslhandler(int fd) : bdatahandler(fd)
{
socklen_t len = (socklen_t)sizeof(m_addr);
getpeername(fd, (struct sockaddr *)&m_addr, &len);
};
~dslhandler()
{
cout << "dslhandler::~dslhandler(): fd=" << m_fd;
cout << ", " << inet_ntoa(m_addr.sin_addr) << ":"<< ntohs(m_addr.sin_port);
m_factory->erase(this);
};
int on_read();
int on_command(std::vector<std::string> &);
int send(char data [],int len);
void showid()
{
bid::showid();
cout << ", " << inet_ntoa(m_addr.sin_addr) << ":"<< ntohs(m_addr.sin_port);
};
void set_factory(bhandlerfactory *factory)
{
m_factory = factory;
};
int log_msg(bool, char data[], int len) {};
private:
struct sockaddr_in m_addr;
bhandlerfactory *m_factory;
};
class dslfactory : public bhandlerfactory
{
public:
dslfactory(){};
~dslfactory(){};
public:
bdatahandler *make(int);
bdatahandler *find(bid &id);
void showall();
void erase(bdatahandler *handler)
{
std::list<dslhandler *>::iterator iter;
dslhandler *p;
for (iter = m_handlers_list.begin(); iter != m_handlers_list.end(); iter++)
{
if (handler == *iter)
{
m_handlers_list.erase(iter);
break;
}
}
};
private:
std::list<dslhandler *> m_handlers_list;
};
#endif