forked from grpc/grpc-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx_notify_queue.h
62 lines (52 loc) · 1.91 KB
/
nginx_notify_queue.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
/**
*
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef NET_GRPC_GATEWAY_RUNTIME_NGINX_NOTIFY_QUEUE_H_
#define NET_GRPC_GATEWAY_RUNTIME_NGINX_NOTIFY_QUEUE_H_
// NOTE: Required on top in order to include ngx_config.h libc defines
#include "net/grpc/gateway/nginx_includes.h"
#include <deque>
#include <memory>
#include "net/grpc/gateway/runtime/tag.h"
#include "third_party/grpc/include/grpc/support/sync.h"
namespace grpc {
namespace gateway {
// The queue which dispatch async IO events back to the Nginx main event loop
// for processing. It's a singleton, since Nginx uses a global socket fd for its
// notify mechanism.
class NginxNotifyQueue {
public:
// Returns the singleton of NginxNotifyQueue.
static NginxNotifyQueue& Get();
virtual ~NginxNotifyQueue();
NginxNotifyQueue(const NginxNotifyQueue&) = delete;
NginxNotifyQueue& operator=(const NginxNotifyQueue&) = delete;
// Add a Tag to the nginx notify queue, its callback will be invoked in the
// main nginx event loop later.
void Add(std::unique_ptr<Tag> tag);
private:
static void NginxNotifyEventsCallback(ngx_event_t* event);
NginxNotifyQueue();
void ProcessEvents(ngx_event_t* event);
gpr_mu mutex_;
ngx_event_t notify_;
bool waiting_for_notify_;
std::deque<std::unique_ptr<Tag>> queue_;
};
} // namespace gateway
} // namespace grpc
#endif // NET_GRPC_GATEWAY_RUNTIME_NGINX_NOTIFY_QUEUE_H_