blob: 4b72c3f77f0a89dd7a30b4569b957a574d37b776 (
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
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
|
#include "conn.h"
#include <util/network/socket.h>
namespace {
class TBlockingSocketStreams: public THttpServerConn::ISocketStreams {
public:
explicit TBlockingSocketStreams(const TSocket& s)
: Socket_(s)
, Input_(Socket_)
, Output_(Socket_)
{
}
IInputStream* Input() override {
return &Input_;
}
IOutputStream* Output() override {
return &Output_;
}
void Reset() override {
if (Socket_ != INVALID_SOCKET) {
// send RST packet to client
Socket_.SetLinger(true, 0);
Socket_.Close();
}
}
private:
TSocket Socket_;
TSocketInput Input_;
TSocketOutput Output_;
};
}
THttpServerConn::THttpServerConn(const TSocket& s)
: THttpServerConn(s, s.MaximumTransferUnit())
{
}
THttpServerConn::THttpServerConn(const TSocket& s, size_t outputBufferSize)
: THttpServerConn(MakeHolder<TBlockingSocketStreams>(s), outputBufferSize)
{
}
THttpServerConn::THttpServerConn(THolder<ISocketStreams> socketStreams, size_t outputBufferSize)
: SocketStreams_(std::move(socketStreams))
, BufferedOutput_(SocketStreams_->Output(), outputBufferSize)
, HttpInput_(SocketStreams_->Input())
, HttpOutput_(&BufferedOutput_, &HttpInput_)
{
}
THttpServerConn::~THttpServerConn() {
}
void THttpServerConn::Reset() {
return SocketStreams_->Reset();
}
|