-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththreadedacceptor.hpp
75 lines (56 loc) · 2.13 KB
/
threadedacceptor.hpp
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
/*
Socle - Socket Library Ecosystem
Copyright (c) 2014, Ales Stibal <[email protected]>, All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
*/
#ifndef _THREADED_ACCEPTOR_HPP_
#define _THREADED_ACCEPTOR_HPP_
#include <hostcx.hpp>
#include <baseproxy.hpp>
#include <masterproxy.hpp>
#include <threadedworker.hpp>
#include <vector>
#include <deque>
#include <thread>
#include <mutex>
#include <mpstd.hpp>
#include <fdq.hpp>
template<class Worker>
class ThreadedAcceptor : public baseProxy, public FdQueueHandler, public hasWorkers<Worker> {
public:
explicit ThreadedAcceptor (std::shared_ptr<FdQueue> fdq, baseCom *c, proxyType type);
~ThreadedAcceptor() override;
void on_left_new_raw(int) override;
void on_right_new_raw(int) override;
int run() override;
proxyType proxy_type() const { return proxy_type_; };
private:
proxyType proxy_type_;
logan_lite log {"com.tcp.acceptor"};
};
template<class SubWorker>
class ThreadedAcceptorProxy : public threadedProxyWorker, public MasterProxy {
public:
ThreadedAcceptorProxy(baseCom* c, uint32_t worker_id, proxyType p):
threadedProxyWorker(worker_id, p),
MasterProxy(c) {}
int handle_sockets_once(baseCom*) override;
static std::atomic_int& workers_total() {
static std::atomic_int workers_total_ = 2;
return workers_total_;
};
private:
raw::dynamic_cast_cache<baseProxy,FdQueueHandler> parent_as_handler;
logan_lite log {"com.tcp.worker"};
};
#endif // _THREADED_ACCEPTOR_HPP_
#include <threadedacceptor.cpp>