blob: f468ca55a66298fca95b0d5d21ab69b4490b42f9 (
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_;
THolder<IThreadPool> ThreadPool_;
THolder<IThreadFactory::IThread> ListenerThread_;
THolder<TInetStreamSocket> SendFinishSocket_;
};
|