-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpServer.h
More file actions
41 lines (33 loc) · 893 Bytes
/
Copy pathHttpServer.h
File metadata and controls
41 lines (33 loc) · 893 Bytes
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
#pragma once
#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
class HttpServer
{
public:
explicit HttpServer(int port);
~HttpServer();
HttpServer(const HttpServer&) = delete;
HttpServer& operator=(const HttpServer&) = delete;
bool start();
void stop();
void pushFrame(std::vector<uint8_t> jpegData);
int clientCount() const { return clientCount_.load(); }
private:
void acceptLoop();
void handleClient(int clientFd);
bool sendAll(int fd, const char* data, size_t len);
int port_;
int listenFd_ = -1;
std::atomic<bool> running_{false};
std::thread acceptThread_;
std::mutex frameMutex_;
std::condition_variable frameCv_;
std::vector<uint8_t> latestFrame_;
uint64_t frameId_ = 0;
std::atomic<int> clientCount_{0};
};