1 | // |
---|---|
2 | // HTTPServerSession.cpp |
3 | // |
4 | // Library: Net |
5 | // Package: HTTPServer |
6 | // Module: HTTPServerSession |
7 | // |
8 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/Net/HTTPServerSession.h" |
16 | |
17 | |
18 | namespace Poco { |
19 | namespace Net { |
20 | |
21 | |
22 | HTTPServerSession::HTTPServerSession(const StreamSocket& socket, HTTPServerParams::Ptr pParams): |
23 | HTTPSession(socket, pParams->getKeepAlive()), |
24 | _firstRequest(true), |
25 | _keepAliveTimeout(pParams->getKeepAliveTimeout()), |
26 | _maxKeepAliveRequests(pParams->getMaxKeepAliveRequests()) |
27 | { |
28 | setTimeout(pParams->getTimeout()); |
29 | this->socket().setReceiveTimeout(pParams->getTimeout()); |
30 | this->socket().setSendTimeout(pParams->getTimeout()); |
31 | } |
32 | |
33 | |
34 | HTTPServerSession::~HTTPServerSession() |
35 | { |
36 | } |
37 | |
38 | |
39 | bool HTTPServerSession::hasMoreRequests() |
40 | { |
41 | if (!socket().impl()->initialized()) return false; |
42 | |
43 | if (_firstRequest) |
44 | { |
45 | _firstRequest = false; |
46 | --_maxKeepAliveRequests; |
47 | return socket().poll(getTimeout(), Socket::SELECT_READ); |
48 | } |
49 | else if (_maxKeepAliveRequests != 0 && getKeepAlive()) |
50 | { |
51 | if (_maxKeepAliveRequests > 0) |
52 | --_maxKeepAliveRequests; |
53 | return buffered() > 0 || socket().poll(_keepAliveTimeout, Socket::SELECT_READ); |
54 | } |
55 | else return false; |
56 | } |
57 | |
58 | |
59 | SocketAddress HTTPServerSession::clientAddress() |
60 | { |
61 | return socket().peerAddress(); |
62 | } |
63 | |
64 | |
65 | SocketAddress HTTPServerSession::serverAddress() |
66 | { |
67 | return socket().address(); |
68 | } |
69 | |
70 | |
71 | } } // namespace Poco::Net |
72 |