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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <drizzled/plugin/plugin.h>
#include <drizzled/atomics.h>
#include <vector>
#include <drizzled/visibility.h>
namespace drizzled {
namespace plugin {
typedef std::vector<Listen *> ListenVector;
typedef std::pair<std::string*, drizzled::atomic<uint64_t>*> ListenCounter;
/**
* This class is used by client plugins to provide and manage the listening
* interface for new client instances.
*/
class DRIZZLED_API Listen : public Plugin
{
Listen();
Listen(const Listen&);
Listen& operator=(const Listen&);
protected:
std::vector<ListenCounter*> counters;
public:
explicit Listen(std::string name_arg)
: Plugin(name_arg, "Listen")
{}
virtual ~Listen()
{
std::vector<ListenCounter*>::iterator it;
for (it= counters.begin(); it < counters.end(); ++it)
{
ListenCounter* counter= *it;
delete counter->first;
delete counter;
}
}
static ListenVector &getListenProtocols();
std::vector<ListenCounter*>& getListenCounters()
{
return counters;
}
/**
* This provides a list of file descriptors to watch that will trigger new
* Client instances. When activity is detected on one of the returned file
* descriptors, getClient will be called with the file descriptor.
* @fds[out] Vector of file descriptors to watch for activity.
* @retval true on failure, false on success.
*/
virtual bool getFileDescriptors(std::vector<int> &fds)= 0;
/**
* This provides a new Client object that can be used by a Session.
* @param[in] fd File descriptor that had activity.
*/
virtual plugin::Client *getClient(int fd)= 0;
/**
* Add a new Listen object to the list of listeners we manage.
*/
static bool addPlugin(Listen *listen_obj);
/**
* Remove a Listen object from the list of listeners we manage.
*/
static void removePlugin(Listen *listen_obj);
/**
* Setup all configured listen plugins.
*/
static bool setup(void);
/**
* Accept a new connection (Client object) on one of the configured
* listener interfaces.
*/
static plugin::Client *getClient(void);
/**
* Some internal functions drizzled require a temporary Client object to
* create a valid session object, this just returns a dummy client object.
*/
static plugin::Client *getNullClient(void);
/**
* Shutdown and cleanup listen loop for server shutdown.
*/
static void shutdown(void);
};
} /* namespace plugin */
} /* namespace drizzled */
|