forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker_impl.h
66 lines (53 loc) · 1.98 KB
/
worker_impl.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
#pragma once
#include <functional>
#include <memory>
#include "envoy/api/api.h"
#include "envoy/network/connection_handler.h"
#include "envoy/server/guarddog.h"
#include "envoy/server/listener_manager.h"
#include "envoy/server/worker.h"
#include "envoy/thread_local/thread_local.h"
#include "common/common/logger.h"
#include "common/common/thread.h"
#include "server/test_hooks.h"
namespace Envoy {
namespace Server {
class ProdWorkerFactory : public WorkerFactory, Logger::Loggable<Logger::Id::main> {
public:
ProdWorkerFactory(ThreadLocal::Instance& tls, Api::Api& api, TestHooks& hooks,
Event::TimeSystem& time_system)
: tls_(tls), api_(api), hooks_(hooks), time_system_(time_system) {}
// Server::WorkerFactory
WorkerPtr createWorker(OverloadManager& overload_manager) override;
private:
ThreadLocal::Instance& tls_;
Api::Api& api_;
TestHooks& hooks_;
Event::TimeSystem& time_system_;
};
/**
* A server threaded worker that wraps up a worker thread, event loop, etc.
*/
class WorkerImpl : public Worker, Logger::Loggable<Logger::Id::main> {
public:
WorkerImpl(ThreadLocal::Instance& tls, TestHooks& hooks, Event::DispatcherPtr&& dispatcher,
Network::ConnectionHandlerPtr handler, OverloadManager& overload_manager);
// Server::Worker
void addListener(Network::ListenerConfig& listener, AddListenerCompletion completion) override;
uint64_t numConnections() override;
void removeListener(Network::ListenerConfig& listener, std::function<void()> completion) override;
void start(GuardDog& guard_dog) override;
void stop() override;
void stopListener(Network::ListenerConfig& listener) override;
void stopListeners() override;
private:
void threadRoutine(GuardDog& guard_dog);
void stopAcceptingConnectionsCb(OverloadActionState state);
ThreadLocal::Instance& tls_;
TestHooks& hooks_;
Event::DispatcherPtr dispatcher_;
Network::ConnectionHandlerPtr handler_;
Thread::ThreadPtr thread_;
};
} // namespace Server
} // namespace Envoy