forked from uroni/urbackup_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServiceWorker.h
64 lines (45 loc) · 1.2 KB
/
ServiceWorker.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
#pragma once
#include <vector>
#include <utility>
#include <stack>
#include "Interface/Thread.h"
#include "Interface/Mutex.h"
#include "Interface/Condition.h"
#include "Interface/Pipe.h"
#include "socket_header.h"
#include "Interface/CustomClient.h"
const int MAX_CLIENTS=20;
class IService;
class CStreamPipe;
class CServiceWorker : public IThread, IRunOtherCallback
{
public:
CServiceWorker(IService *pService, std::string pName, IPipe * pExit, int pMaxClientsPerThread);
~CServiceWorker();
void operator ()(void);
int getAvailableSlots(void);
void AddClient(SOCKET pSocket, const std::string& endpoint);
void stop(void);
virtual void runOther();
struct SCurrWork
{
ICustomClient* client;
bool did_other_work;
};
private:
void work(ICustomClient* skip_client);
void addNewClients(void);
std::vector<std::pair<ICustomClient*, CStreamPipe*> > clients;
std::vector<std::pair<SOCKET, std::string> > new_clients;
IMutex* mutex;
IMutex* nc_mutex;
ICondition* cond;
IPipe *exit;
int nClients;
int max_clients;
THREAD_ID tid;
std::string name;
IService *service;
volatile bool do_stop;
std::stack<SCurrWork> curr_work;
};