blob: f9f728712690011f38a0f447e2e8acf354bb035c (
plain) (
blame)
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
|
#pragma once
#include <util/generic/ptr.h>
#include <util/stream/input.h>
#include <util/stream/output.h>
#include <util/thread/pool.h>
#include <functional>
class TInetStreamSocket;
// Simple server listens on the specified port and launches
// requestHandler in the separate thread for each incoming connection.
class TSimpleServer
{
public:
using TRequestHandler = std::function<void(IInputStream* input, IOutputStream* output)>;
public:
TSimpleServer(int port, TRequestHandler requestHandler);
~TSimpleServer();
void Stop();
int GetPort() const;
TString GetAddress() const;
private:
const int Port_;
std::unique_ptr<IThreadPool> ThreadPool_;
THolder<IThreadFactory::IThread> ListenerThread_;
std::unique_ptr<TInetStreamSocket> SendFinishSocket_;
};
|